So im in the middle of making my 2D infinite runner using C# script and my SPIKE that is to destroy and Respawn my Player but it will sometimes duplicate my character 2-3 times if i land on the spike on an angle (both character and spike have box colliders but the spikes collider can be altered)
i should also note Player is a prefab
If anyone has anything that could help me i would appreciate im an amateur hoping to improve
here is what i have so far
public class SPIKE1 : MonoBehaviour {
public GameObject Player;
public Transform SpawnPoint;
private bool respawn = false;
void OnCollisionStay2D(Collision2D coll)
{
if (coll.gameObject.tag == "Player")
Destroy(coll.gameObject);
if (respawn)
return;
if (coll.gameObject.tag == "Player")
Instantiate(Player, SpawnPoint.position, SpawnPoint.rotation);
SendMessage("respawn");
}