I have a scene which involves several characters walking around. Currently when they pass a certain threshold distance to the camera, they switch from one character object to another. I want to continue doing this, but use a box collider and the OnTriggerEnter and OnTriggerExit events instead.
I created my empty game object, added my box collider, checked “Is Trigger”, added a RigidBody component and unchecked “Is Kinematic” and “Use Gravity”, and moved it into place. I added the following basic script to it to just print out a message when one of my characters encounters it:
using UnityEngine;
using System.Collections;
public class AvatarSwitcher : MonoBehaviour {
/*
* AvatarSwitcher.cs
* by Aaron Siegel, 9-1-10
*
* Attached to a large invisible box collider used to detect onTriggerEnter and Exit events
* in order to switch
*/
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter (Collider other) {
print(other +" has entered");
}
void OnTriggerExit (Collider other) {
print(other +" has exited");
}
}
The thing that baffles me at this point is that I only get the print messages once. The first character that interacts with the box triggers the enter/exit events, but after that none of them seem to have any effect.