i have a button to restart the same scene but it dont works (with images)

i have many many things but no one of them worked

i had created an empty gameobject and attached this script to it then put the gameobject into the button’s ONCLICK and then choosen the public function of the script

then when i play the the game the button dont work i dont understand why

i have only one scene and when the players die the button be activated 'i have done this in onother script"
i click the button to restart the scene…

this is he script:

using UnityEngine.SceneManagement;
using UnityEngine;

public class RESTART : MonoBehaviour {

public void restart()
{
	//SceneManager.LoadScene (SceneManager.GetActiveScene ().name);

	//Scene loadedLevel = SceneManager.GetActiveScene ();
	//SceneManager.LoadScene (loadedLevel.buildIndex);

	SceneManager.LoadScene("GAME");

	//SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
	
}

}

Are you sure you have an EventSystem in your scene ? No other element which could block the raycast ? During play mode, select the EventSystem in your scene, put the pointer over the button and check in the little "Preview" box at the bottom of the Inspector that you have the name of your button.

7 Answers

7

Hi !

Is your scene in the “Scenes in build” list (in the built settings window) ?

yes and its index is 0 i have only one scene for now

Why is your script commented out?

i tryed all of this comment but no one works

Try using the following code:

SceneManager.LoadScene(SceneManager.GetActiveScene().path);

@dasfuhrer

If it doesn’t work make sure that the button is getting called by some Debug.Log() withing the restart function.

its dont works [97106-problem.png|97106] i write this and nothing debuged SceneManager.LoadScene(SceneManager.GetActiveScene().path); Debug.Log ("clicked");

SceneManager.LoadScene (SceneManager.GetActiveScene ().name);

this has to work?

if it’s not working try that

Application.LoadLevel(0);

this is old ! im with unity 5.5

Not sure what else would cause this. However, I do recommend referencing the objects instead of going off of string paths. String paths can get lost in a build, and software that is used to remove unused content, will not find those references. Can you create a Public GameObject Prefab field, and instantiate from that instead of from a call to Resources? (I'm not sure why this would cause it, but loading it a different way might have some impact.)

Same code, but working with Unity 5.6.0f3

Good Idea, but also did not work im not sure how to fix this i know it is a render problem and maybe it is in the camera do you know if there is any config in the camera?

From what I see in images, you havn’t attached the script to a gameobject and you directly draged it from Project panel into the event slot in inspector (tell me if I’m wrong).

you need to drag the script on a gameobject and drag that gameobject into the slot in the event part of the button

i have added the the "restart.cs" script to an empty game object the putted it in the onclick ^ ^ but dont works !

thank you so much!! I have been trying to figure this out forever :slight_smile: