Dying Script error

I’m trying to make a game like the classic Frogger. But I having a problem with the dying script, In my script I put a void that is something like this:

void OnTriggerEnter2D (Collider2D other){
		Debug.Log("Object " + other.name );
		player.transform.parent = other.transform;
       }

So, every time that the player hits a log, the frog becames a child of this log and goes floating with it. And every time that the player moves foward the player parent = null, and when parent = null the player dies. My problem is, some times the frog is on top of the log but they do not collide !! and the player died, but most of the time it works fine. Can someone help me ?

P.S: Sorry for my english.

It sounds like a logic error to me. We don’t want to set the parent to null until we are sure we missed the next log. What I can see happening is you press forward, set the parent to null, then the log detection occurs. Some things like Update() and OnCollisionEnter() are asynchronous. This means we can’t be sure (without some controls) which one will be running when. If the Update() loop is what checks null and handles it, it may check before the collision check occurs.

One way to handle this would be a flag that says if we have made a move, if we have, wait for the collision check to occur before handling null. The other way would be to set null in the collision script. Either way I believe your problem is there and in how, and what order, the events “may” occur in.

you are not checking to see what you collided with, just to see if you collided.

if(other.gameObject.tag != "log") //or whatever
{
die();
}
else
{
player.transform.parent = other.transform;

}