I have a mesh with a collision primitive attached (box) and a player controllable rigidbody object with a spherical collider.
The mesh’s collision is set to IsTrigger, and it has a script containing a simple script (from the manual) with an OnCollisionEnter function to set an animation playing:
var player : GameObject;
var target : GameObject;
function Update () {
OnTriggerEnter(player.collider);
}
function OnTriggerEnter (other : Collider)
{
Destroy(other.gameObject);
print("Collided");
target.animation.Play();
}
The player object is destroyed when entering the collision, so that much is working. However, the print message appears and the animation starts playing as soon as I hit Play in Unity.
Clearly I’m doing something wrong…but what?