How can I change this script to play a sound on collision? I’ve tried many things but nothing seems to work.
I already made this to make objects vanish when hit with a rigidbody.
function OnCollisionEnter(collision : Collision) {
//if(collision.gameObject.tag == "Destroyer")
Destroy(gameObject);
}
The “SoundObject” is A Game Object with an “Audio Source” Component added to it.
The Sound Clip is already applied.
GameObject.Find("SoundObject").audio.Play();
if you need to set the sound Clip before
var sound:AudioClip = "someaudio_clip";
GameObject.Find("SoundObject").audio.clip = sound;
GameObject.Find("SoundObject").audio.Play();
So:
function OnCollisionEnter(collision : Collision) {
//if(collision.gameObject.tag == "Destroyer")
GameObject.Find("SoundObject").audio.Play();
}
I have tried that script it just gives me the following error (unknown identifier other clip) sorry if its my fault I’m new to unity