Okay, have a simple bit of code. Player (rigidbody with collider, no charcontroller) moves, hits a cube set up as a trigger (box collider, no rigidbody). Cube has an onTriggerEnterscript attached that parents the player to another cube (parentCube, collider, no RB). There’s also an onTriggerExit code attached to the cube but this is never triggered (no message in the console).
So I figured maybe it’s because the player is now a child and doesn’t register as a collider BUT it does. onTriggerEnter is still reported in the debug console but never onTriggerExit. If I create another cube with onTriggerEnter script on it the cild-player will happily trigger it - no problem. So my questions is why do the triggers register onTriggerEnter but not onTriggerExit. Bug or am I missing something? Here’s the code. Any help much appreciated.
private var steps : GameObject;
function Start () {
steps = GameObject.Find("parentCube");
}
function OnTriggerEnter (other : Collider) {
Debug.Log("Entered");
// find the script attached to the player
var otherScript = other.GetComponent(newController);
// turn off controller
otherScript.canControl = false;
// Get the transform of the player
var playerTransform = other.transform;
// Get transform of the steps object
var stepsTransform = steps.transform;
// make player a child of the steps object
playerTransform.parent = stepsTransform;
// turn off gravity
if (other.attachedRigidbody) {
other.attachedRigidbody.useGravity = false;
}
// Get script attached to steps
var stepscript = steps.GetComponent(CubeController);
// enable control of the steps object
stepscript.canControl = true;
}
function OnTriggerExit (other : Collider) {
Debug.Log("Exit");
var stepscript = steps.GetComponent(CubeController);
stepscript.canControl = false;
var playerTransform = other.transform;
// un-child
playerTransform.parent = null;
// find the script attached to the player
var otherScript = other.GetComponent(newController);
// turn on controller
otherScript.canControl = true;
// turn on gravity
if (other.attachedRigidbody) {
other.attachedRigidbody.useGravity = true;
}
}