I know that this question has been asked many times before but I have searched for 2 hours and nothing works. I need a script that resets the scene when the player collides with an object. Please help, I’m am so irritated. (Please use JavaScript) This is 2D
-
Name of player: Player.
-
Name of Object: Obstacle 1
-
Name of Scene: Maze1
I FINALLY FOUND THE ANSWER!!! I AM SO HAPPY!!!
#pragma strict
function OnCollisionEnter2D (col : Collision2D)
{
if(col.gameObject.name == "Obstacle1")
{
Application.LoadLevel("Maze1");
}
}
YESSS!
Thanks so much to everyone who helped me
Gena rally the error come if some of code in the class is be written out of the class means (your code may be written after closing the bracket of mono behavior).
here you are missing the class name.may this one
using UnityEngine;
using UnityEngine.SceneManagement;
private void OnCollisionEnter(Collision collide)
{
if (collide.gameObject.name == "Obstacle1")
{
SceneManager.LoadScene("Maze1");
}
}