- Home /
Box collider not triggering OnCollisionEnter
I have a small terrain that I'm using with the FirstPersonCharacter.
I create a Cube, uncheck the Mesh Renderer and check Is Trigger.
I create this script, Trigger.cs:
using UnityEngine;
using System.Collections;
public class Trigger : MonoBehaviour {
void OnCollisionEnter(Collision collision) {
Debug.Log ("OnCollisionEnter");
}
}
I drag the script to the Cube and then run the game. I walk into the trigger area, but no message is displayed in the debug console. What step did I miss?
Comment
Answer by tanoshimi · Jul 15, 2015 at 05:42 AM
Triggers don't set off OnCollisionEnter. They set off OnTriggerEnter.
http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
Answer by Hrungdak · Jul 15, 2015 at 05:43 AM
If the cubes Box collider is a trigger, then you should use OnTriggerEnter(). Also the cube or the terrain must have a rigidbody.