- Home /
3 errors in scrip.
Hi i am a new member to the unity type of thing, and i am experiencing 3 problems when writing a small code, i am trying to add a sound trigger to my horror game that i am working on, so when you pass a certain area, a scary sound appears, and this is the code that i put in.
var Sound : AudioClip; -function OnTriggerEnter(){ audio.PlayOneShot(sound); }
Im not sure whats wrong with it, but i got 3 errors which are expecting :, found ';'. and ';' expected. Insert a semicolon at the end. and lastly expecting (, found 'OnTriggerEnter'.
If anyone can please help me with this issue, it would be awesome.
Answer by voncarp · Jul 24, 2012 at 10:05 AM
Looks like your variables don't match. Try a lowercase "s" for sound. Also, you probably want to add something to register that the player has entered the trigger:
var sound : AudioClip;
function OnTriggerEnter(other : Collider) {
if (other.tag == "Player") {
audio.PlayOneShot(sound);
}
}
Make sure your collider is set to isTrigger. And your player tag is set to "Player"
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
what is wrong with this online FPS script(not done) ? 1 Answer
Multiplayer Script error 2 Answers
Expecting ':' Found '=' Error 1 Answer