- Home /
 
 
               Question by 
               showthebelt · Jan 27, 2021 at 02:10 AM · 
                gameover  
              
 
              Trouble with Gameover screen.
Hi,
I'm having trouble with a gameover screen. And I've been working on it for around 2 weeks and I couldn't find a solution for it. I was using Youtube and I couldn't find it one in C# there either. Please find bellow the C# code I am using.
Thanks in Advance.
 // Start is called before the first frame update
 void Start()
 {
      currentHealth = maxHealth;
     healthbar.SetMaxHealth(maxHealth);
 }
 // Update is called once per frame
 void Update()
 {
   
 }
 void OnCollisionEnter2D(Collision2D col)
 {
     if(col.gameObject.tag == "Enemy")
     {
         TakeDamage(1);
     }
 }
 void TakeDamage(int damage)
 {
     currentHealth -= damage;
     healthbar.SetHealth(currentHealth);
 }
  
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by RealFolk · Jan 28, 2021 at 12:58 PM
Make a scene called GameOver.
 void TakeDamage(int damage)
      {
          currentHealth -= damage;
          healthbar.SetHealth(currentHealth);
          
          if(currentHealth <= 0)
     {
     // go to gameover scene
 UnityEngine.SceneManagement.SceneManager.LoadScene("GameOver")
     }
      }
 
 
 
 
              I'm pretty sure there is 100s of tutorials on youtube on how to do this.
Your answer