I’m creating a bomberman2D - like game. I want to check who Instantiated the bomb .
So far I have done it like this :
private GameObject Player = null;
private void OnTriggerEnter2D(Collider2D collider)
{
if (collider.gameObject.CompareTag("Player") && Player == null)
{
Player = collider.gameObject;
Debug.Log("The player who set a bomb is : " + Player.name);
}
}
void OnTriggerExit2D(Collider2D other)
{
boxCollider.isTrigger = false;
}
The problem appears when two players are in the same place and one of them is dropping a bomb. It works for one of them, but not for the both - like Unity is “seeing” the collision of one of them as first. How can I refer to the gameObject that Instantiated the bomb in another way?