- Home /
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.
Answer by Cycy · Jun 28, 2017 at 02:49 PM
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
Answer by Ashokkumar-M · Jul 03, 2017 at 05:39 AM
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
i write this and nothing debuged
Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().path); Debug.Log ("clicked");
Answer by efeguclu · Jul 04, 2017 at 12:31 PM
SceneManager.LoadScene (SceneManager.GetActiveScene ().name);
this has to work?
if it's not working try that
Application.LoadLevel(0);