32 lines
779 B
C#
32 lines
779 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(AudioSource))]
|
|
public class PitchRandomizer : MonoBehaviour
|
|
{
|
|
[Range(0f, 0.1f)]
|
|
[SerializeField] private float pitchDeviationRange;
|
|
AudioSource source;
|
|
[SerializeField] private bool useStablePitchInstead = false;
|
|
[Range(-0.12f, 0.12f)]
|
|
[SerializeField] private float stablePitchDeviation;
|
|
|
|
private void Awake()
|
|
{
|
|
source = GetComponent<AudioSource>();
|
|
}
|
|
|
|
public void RandomizePitch()
|
|
{
|
|
if (useStablePitchInstead)
|
|
{
|
|
source.pitch = 1 + stablePitchDeviation;
|
|
}
|
|
else
|
|
{
|
|
source.pitch = 1 + Random.Range(-pitchDeviationRange, pitchDeviationRange);
|
|
}
|
|
}
|
|
}
|