So look: I have a monster in the game that when player collides with him a panel appears and says try again. There is now a shield object, that will protect the player from death, so when the player collides with it and then if you touch the monster you shouldn't die for one time: it will be like that, you touch the shield and you are protected from one death. Can you help me write this code?
public GameObject panel;
public bool hasShield = false; /* no shield in the beginning */
void OnCollisionEnter(Collision col)
{
if(col.gameObject.tag == "Shield")
{
hasShield = true; //We are safe now.
/* TODO: StartCoroutine() or Invoke() to reset the variable and the graphic effect after some amount of time. */
}
else if (col.gameObject.tag == "Monster" && !hasShield)
{
//We hit a monster and had no shield. Display gameover.
panel.SetActive (true);
}
//I assume the panel is inactive by default so no need to call SetActive(false) on it.
}