Problem with getting a block to be destroyed on collision with player

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();
   }
}

Thank you in advance!

Put a Debug.Log(“is it working?”); inside “if (collision.gameObject.tag == “KillBox”) {” and see if it triggers at all.

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();
   }
}

You added an extra equals symbol in here, at line 11,

audio.clip = Narrative1;
audio.Play();

You will probably have to change line 1 to this also,

var Narrative1 : audioClip;

edits : formatting and readability.

Without the extra = symbol, it gives me errors, as well as the audioClip,

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.

http://docs.unity3d.com/Documentation/ScriptReference/Collider.html

Sorry chap, should have been capitalised.

var Narrative1 : AudioClip;