In my game there are 2 players, Player1-a and Player2, when the players collide, the text on each one of them is changing (Player1-a is Player1 and Player2 is Player2-a). The problem is that it keeps changing texts while the players are colliding (it can switch the texts 2 times for one collision) and i want it to change the texts only one time per collision. And I also need that after a collision it wont be able change texts for 5 seconds because if they will collide again after 1 second it will change the texts again).
This is the player1 collision action:
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("TriggerOn"))
{
if (firstPlayerText.text == "Player1-a")
{
firstPlayerText.text = "Player1";
secondsPlayerText.text = "Player2-a";
}
}
}
and this is the collision action of the other player:
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("TriggerOn2"))
{
if (secondsPlayerText.text == "Player2-a")
{
firstPlayerText.text = "Player1-a";
secondsPlayerText.text = "Player2";
}
}
}
By the way I also want that after the collision, the player2 with the new text (player2-a) wont be able to move for 5 seconds.