Hey guys, I have this script, it doesn’t seem to recognize the raycast, it plays sounds every time I press Z, not what I want. I only want it to happen when you touch the object with the script applied. I can’t seem to figure out the structure
var sound1: AudioClip;
var sound2: AudioClip;
var sound3: AudioClip;
var sound4: AudioClip;
private var radio = "off";
function Update(){
if(Input.GetKeyDown("z")){
{
var hit : RaycastHit;
if (Physics.Raycast(transform.position,
transform.forward, hit, 0.2F))
{
}
if(radio == "off"){
radio = "sound1";
}
else if(radio == "sound1"){
radio = "sound2";
}
else if(radio == "sound2"){
radio = "sound3";
}
else if(radio == "sound3"){
radio = "sound4";
}
else if(radio == "sound4"){
radio = "sound1";
}
if(radio == "sound1"){
Debug.Log("sound is playing");
audio.clip = sound1;
audio.Play();
}
else if(radio == "sound2"){
audio.clip = sound2;
audio.Play();
}
else if(radio == "sound3"){
audio.clip = sound3;
audio.Play();
}
else if(radio == "sound4"){
audio.clip = sound4;
audio.Play();
}
}
}
}