Hi,
I am trying to make a car collide with an object, but its not triggering a print. Any ideas?
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "gem"){
print("n");
}
}
Hi,
I am trying to make a car collide with an object, but its not triggering a print. Any ideas?
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "gem"){
print("n");
}
}
For this to work, your car object must be a character controller or have a rigidbody, and the object you’re trying to hit must have a rigidbody too. Also the object tag must match “gem” exactly (tags are case sensitive).
By the way, if this “gem” object is something which must disappear and give points to your car when hit, it’s better to use a trigger instead: just check Is Trigger in the collider and use OnTriggerEnter(collider:Collider) instead of OnCollisionEnter - triggers don’t need rigidbodies. More information on:
http://unity3d.com/support/documentation/ScriptReference/Collider.OnTriggerEnter.html