R
R
Ronex2020-08-20 15:26:04
Unity
Ronex, 2020-08-20 15:26:04

Unity C# - How to make a level restart 2-3 seconds after character death?

Guys, help me solve the problem, otherwise my head is already swollen. I am just starting my journey in learning C# and Unity respectively.

Problem:
The player "disappears" when touching the "Enemy" tag and after that it is necessary to restart the level. I have already reviewed hundreds of articles and videos, not a single proposed option works.

Here is the code:

private void OnCollisionEnter2D(Collision2D other)
        { 
            if (other.gameObject.tag == "Enemy")
               {
                  Instantiate(deathplayer, transform.position, Quaternion.identity);
                  this.gameObject.SetActive (false);
                }
         }


The Particle system is attached to the deathplayer so that when the GG dies, it nicely disintegrates.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GFX Data, 2020-08-21
@Ronex

What does it mean - "the proposed option does not work?"
It seems not difficult.

Invoke("Restart", 3f);

void Restart()
{
    SceneManager.LoadScene("LevelScene", LoadSceneMode.Single);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question