Hey guys.
I am making a game, in which i have a problem. I want my player to die and the level to restart when it collides with my enemy game object i am very noob so please explain in details for a noob
Hey guys.
I am making a game, in which i have a problem. I want my player to die and the level to restart when it collides with my enemy game object i am very noob so please explain in details for a noob
void OnTriggerEnter (Collider other) {
if (other.CompareTag (“enemy”)) {
SceneManager.LoadScene (0); //the number of the scene you want
}
}
This should work, it will reset the scene right after your character enters a trigger (at least one of the objects must have rigidbody).
You have to write on top of your script using UnityEngine.SceneManagement
If your game is 2D dont forget that’s OnTriggerEntrer2D and Collider2D.
Hope this helps.