function update problem

Hi there…I would like to vary a sound’s pitch each time it is triggered…this script seems to vary once on the scene start,but not afterwards…

function Update () {
      var startingPitch : float;             
      audio.pitch = startingPitch + (Random.Range(0.1,2.0));
      audio.Play();
               
}

Also…do I attach this script to the sample itself,or the gameobject?

Apologies for newbiness…just beginning unity recently…cheers!

1 Answer

1

Attach the game object, because you use audio.

And it is not use the Update. Use this

var changePitchRate = 0.3

InvokeRepeating("ChangePitch", 1, changePitchRate);

function ChangePitch ()
{
    var startingPitch : float;             
    audio.pitch = startingPitch + (Random.Range(0.1,2.0));
    audio.Play();
}

but what the startingPitch do? The startingPitch is 0.