title: Trying to get death and respawn working in my game
body: <p>I can't get my respawning in my game to work, I have followed numerous tutorials, but have been failing to change one small aspect of them. I have a health variable in my game, and all the tutorials have the player die and respawn right upon touching the enemy. I want it to be so you take damage when touching an enemy, and when your health reaches 0 you are brought to a game over scene. I just can't seem to figure it out. I am new to game dev so I have tried my absolute hardest to solve the problem on my own, but to no avail. This is pretty much my last resort. I appreciate any help I can get.</p>
  <pre><code>using System;
  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.SceneManagement;
  
  public class PlayerHealth : MonoBehaviour
  {
  
  public static PlayerHealth instance;
  
  public int maxHealth;
  public int health;
  public int GameOver;
  
  
  public event Action DamageTaken;
  
  
  public int Health
  {
      get
      {
          return health;
      }
  }
  
  
  // Start is called before the first frame update
  void Awake()
  {
      
  
      if(instance == null)
      {
          instance = this;
      }
  }
  
  private void Start()
  {
      health = maxHealth;
  }
  
  // Update is called once per frame
  public void TakeDamage()
  {
      if(health &lt;= 0)
      {
          return;
      }
      health -= 1;
      if(DamageTaken != null)
      {
          DamageTaken();
      }
  }
  
  public void heal()
  {
      if (health &gt;= maxHealth)
      {
          return;
      }
      health += 1;
      if (DamageTaken != null)
      {
          DamageTaken();
      }
  }
  
  void OnCollisionEnter(Collision other)
  {
      if(other.gameObject.tag == &quot;Enemy&quot;)
      {
          TakeDamage();
      }
  
      if(health &lt;= 0)
      {
          SceneManager.LoadScene(GameOver);
      }
  }
  }
  </code></pre>