I’m currently creating a flight game and today I decided to implement simple engine sounds. Changing the pitch worked fine, but when I decided to implement a different sound for when the thrust is high and low.
The code’s simple:
this is hard to correct cause we can’t see the rest of your code and your lookups. but I cant see why you are trying to change the pitch and the clip differently.
actually even if you are not getting errors, if you keep calling it like you are showing you will find you cant keep updating the component, but you do need to keep checking the value. so you need another varible to check if the statis has changed.
this should work:
public AudioClip somemp3; //<---drag mp3 into the inspector here
public AudioClip nextmp3; //<---drag mp3#2 into the inspector here
AudioSource audio;
int current;
void Start() {
// you need a reference to your component
audio=gameObject.GetComponent<AudioSource>();
}
// now you should be able to say this anywhere else in your code
void Update(){
if(whatever){
if(current!=0){current=0;
audio.clip=somemp3;
audio.pitch=.5f;
audio.Play();
}
}else{
if(current!=1){current=1;
audio.clip=nextmp3;
audio.pitch=.8f;
audio.Play();
}
}