Hey Unity users, I wanted to redo my question since last time. I kinda forgot to include the question in that one, sorry it was my first post. But anyway I am making a horror game and want the walking sound to change when I move form grass to gravel. I want the sound effect to change. The script works as far as compiler errors. TRge only problem is when I enter the collision box to mark the gravel sound, the grass sound just keeps playing and the gravel sound never starts. Please help.
This is my code:
#pragma strict
var Sound : AudioClip;
var Sound2 : AudioClip;
function Update () {
if(Input.GetKeyDown("w")){
audio.clip = Sound;
audio.Play();
}
if(Input.GetKeyUp("w")){
audio.Stop();
}
}
function OnCollisionEnter(collision : Collision){
if(Input.GetKeyDown("w")){
}
if(collision.gameObject.tag == "Gravel"){
audio.Stop();
audio.clip = Sound2;
audio.Play();
}
else if(Input.GetKeyUp("w")){
audio.Stop();
}
}
in future, please format your code by highlighting then clicking the 101010 button, and use better tags. Alucard Jay