I created a simple scene to test this:
- Two cubes
- Two materials for giving each one different colors
- Each one have a box collider attached
- The one i move have also a rigidbody attached (with Use gravity unchecked)
- The other one doesn’t have any rigidbody, and its collider is configured as a trigger
I created this simple script:
using UnityEngine;
using System.Collections;
public class OverlapTest : MonoBehaviour {
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
void OnTriggerStay(Collider collider)
{
Debug.Log("Overlapping '" + collider.gameObject.name + ".");
}
void OnTriggerEnter (Collider collider)
{
Debug.Log("Overlap enter.");
}
void OnTriggerExit (Collider collider)
{
Debug.Log("Overlap exit.");
}
}
and attached it to the one that have the rigidbody.
When i click Play, i move the cube with the rigidbody and the script directly by modifying the X value in its transform component until i touch the other cube.
The OnTriggerEnter and OnTriggerExit methods are called succesfully, but ONLY THE FIRST TIME i enter and exit the other cube.
If i try another time, i get no more “Overlap enter” and “Overlap exit” messages.
And the OnTriggerStay method… only fires one time while i’m inside the other cube.
See ya!