OnTriggerEnter & OnTriggerExit

Hi,

I am working on Frogger clone game: I am having an issue with logs part.

What I am doing is : i check if the frogs transform.position.y== thefirstlog.transform.position.y then i check a flag if the frog hit any log or nothing.

var safe:boolean=false;
var thefirstlog:Transform;

function Update(){

/*the movement code up down left right
......................
 end movement */
CheckCollision();

}

function OnTriggerEnter(other:Collider){
if(other.CompareTag("log")){

//make log the parent
transform.parent=other.transform;

safe=true;
}
}

function OnTriggerExit(other:Collider){
if(other.CompareTag("log")){

//make log the parent
transform.parent=null;

safe=false;
}
}

function CheckCollision(){
Debug.Log(safe);

// thefirstlog is an empty game object that has the same y position like the logs
if(transform.position.y==thefirstlog.transform.position.y && !safe){

KilltheFrog();
}
}

When I do Debug.Log safe is always false.

Thank you

If the logs are moving triggers, you may have to add a kinematic rigidbody to them - at least the CharacterController isn’t detected by a moving trigger (I have not tested if rigidbodies are detected).