Player doesn't die.
Trying to do something pretty simple and might just be dumb. I'm trying to kill the player when he hits a box on the layer danger, but it isn't working as of now
On player script:
private void Dead()
{
if (rb.IsTouchingLayers(LayerMask.GetMask("Danger")))
{
estaVivo = false;
FindObjectOfType<Gerenciador>().Restart();
}
}
The object 'Gerenciador' is checking in what level the player is
Gerenciador:
public class Gerenciador : MonoBehaviour
{
[SerializeField] float tempoEspera = 2f;
IEnumerator Reiniciar()
{
Time.timeScale = 0.2f;
yield return new WaitForSecondsRealtime(tempoEspera);
Time.timeScale = 1f;
yield return new WaitForSecondsRealtime(tempoEspera);
var cenaAtual = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(cenaAtual);
}
public void Restart()
{
StartCoroutine(Reiniciar());
}
}
Reiniciar restarts level, TempoEspera is the waiting time EstaVivo is to check if the player is alive or not
Comment
Your answer
Follow this Question
Related Questions
death and respawn 0 Answers
Whats a good way to kill player if they go below a certain area? 2 Answers
How do I make it so a death animation will play when I hit an enemy? 0 Answers
Make a Particle System play when Player gets destroyed 0 Answers
Referencing playerHealth (from a separate script) in an if statement 1 Answer