Question by
toadflaxunf · Dec 30, 2017 at 08:26 PM ·
collisiondetectionmeshcollider
Check if I collide with object only ONCE
I'm using the OnCollisionEnter function to check a collision between two objects. This works fine for me, however in a split seconds, the function detects 2 collision instead of one, which means I spawn 2 characters instead of one. Here's my if statement:
void OnCollisionEnter(Collision col) {
if (col.gameObject.name == "Target1") {
anim.SetTrigger(jumpHash);
Debug.Log("Spawn?");
spawnNewCharacter.SpawnCharacter();
Debug.Log("Play touched plane!");
}
}
My question is, how can I change this if statement so that it only feeds back 1 collision instead of 2? I've tried using a Boolean to check if it has collided but unfortunately that doesn't work well for me.
Comment