Question by
toadflaxunf · Jan 02, 2018 at 01:19 PM ·
collisiononcollisionenterdetection
Check for collision 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