Hi there, I have been trying to make a simple script that allows me to make the player collide with an object with a certain tag, which will then destroy that object and play a sound attached to the player. However, there are no errors with the script and I have checked with a few people, the cube will not be destroyed, any suggestions?
function OnCollisionStart(collision : Collision)
{
if (collision.gameObject.tag == "KillBox")
{
Destroy(collision.gameObject);
GameObject.Instaniate();
audio.Play();
}
}
After the trial and error I managed to get that working, needed an OnTriggerEnter there instead, my problem with it now is, I can’t get it to play the audio source that I assign it too, which is odd, here is the updated code.
var Narrative1 : AudioSource;
var isDead = false ;
function OnTriggerEnter(hit : Collider)
{
if (hit.gameObject.tag == "KillBox")
{
Destroy(hit.gameObject);
GameObject.Instaniate();
audio.clip == Narrative1;
audio.Play();
}
}
Your original code didn’t work because OnCollisionStart isn’t a valid collision event. You’re choices are Enter, Exit, and Stay for both OnCollision and OnTrigger.