- Home /
OnCollisionEnter If statement error
What's wrong with this script?
function OnCollisionEnter(collision : Collision) { if (collider.gameObject.CompareTag("Level")) { // Rotate the object so that the y-axis faces along the normal of the surface var contact = collision.contacts[0]; var rot = Quaternion.FromToRotation(Vector3.up, contact.normal); var pos = contact.point;
Instantiate(explosionPrefab, pos, rot);
// Destroy the projectile
Destroy (gameObject);
}
}
It works fine without the if statement, but if I add it, nothing happens when my bullet hits something. I've spent way too much time on this, and would appreciate help. There appears to be nothing wrong with it, except the obvious - it's not working. Sigh.
Answer by Peter G · Apr 27, 2010 at 12:20 AM
It looks like you said collider.gameObject when you meant to say:
collision.gameObject.CompareTag();
Your answer
Follow this Question
Related Questions
#ifdef UNITY_IPHONE equivalent for JavaScript 2 Answers
Reverse animation at the point it stopped playing 1 Answer
Script translation 2 Answers
JavaScript error BCE0005 0 Answers
Is there eval() for C#? 2 Answers