1
\$\begingroup\$

Every time I try to click on the button, nothing happens. I am linking some picks to help everyone answer my question.

I have added a event system. I have a canvas. The button is set to interactable.

The restart button script My heirachy Inspector

\$\endgroup\$
5
  • \$\begingroup\$ This could be a weird Unity thing, but try removing the "static" method modifier then use the dropdown menu to select the method (instead of MonoScript.name) \$\endgroup\$ Jun 28, 2015 at 18:50
  • \$\begingroup\$ @MDragon00 I even tried that. Originally it wasn't static, I then tried it out with the static keyword. \$\endgroup\$ Jun 29, 2015 at 5:25
  • \$\begingroup\$ Moreover in the dropdown menu I am just getting a option for no function and Monoscript main function. \$\endgroup\$ Jun 29, 2015 at 5:26
  • \$\begingroup\$ You should change back to non static. It won't work any way. answers.unity3d.com/questions/840906/… \$\endgroup\$
    – SanSolo
    Jun 29, 2015 at 6:49
  • \$\begingroup\$ Regarding non static, trying to find out. \$\endgroup\$
    – SanSolo
    Jun 29, 2015 at 6:49

2 Answers 2

0
\$\begingroup\$

The problem is here: enter image description here it looks like you directly dropped the script instead of the object to which it is attached.

Let's say your "Restart" script is attached to MainCamera. You need to assign Main Camera in the field marked red.Then select a script attached to main Camera, which is Restart, from that select a method which is ReStartGame().

When you do that, the field marked green would say: Restart.RestartGame

\$\endgroup\$
0
0
\$\begingroup\$

Put the Debug.Log before the Loadlevel instruction. What happens now is, LoadLevel is executed and everything is destroyed, including the button which was clicked. When new scene is loaded, everything in current scene is automatically destroyed. If you want an object to be present across multiple scenes, check the manual for DontDestroyOnLoad().

\$\endgroup\$
5
  • \$\begingroup\$ The debug log is just for checking whether the button is being clicked on and still not functions as a restart button. \$\endgroup\$ Jun 28, 2015 at 17:24
  • \$\begingroup\$ @AkshatMalik if you comment out the Application.LoadLevel line and then click the button, does the debug statement still run? (Just a quick test, may help out). And as a side note, you shouldn't need that event system just for a button to activate a public method. \$\endgroup\$ Jun 28, 2015 at 18:49
  • \$\begingroup\$ @AkshatMalik whether you treat it as restart feature or not, it actually is loading new level. Just put Debug.Log before the loadlevel \$\endgroup\$
    – SanSolo
    Jun 29, 2015 at 5:38
  • \$\begingroup\$ @SanSolo well i did, and still nothing happened. \$\endgroup\$ Jun 29, 2015 at 5:41
  • \$\begingroup\$ What is the name of the object to which Restart script is attached? \$\endgroup\$
    – SanSolo
    Jun 29, 2015 at 6:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .