unity3d - Instead of LoadLevel, how do i use SceneManager -
i super new in coding , couldn't find right answer on web. want change scene in game. i've had buttons etc. can't choose "menu" script on click function menus.
all answer welcome!
using unityengine; using unityengine.scenemanagement; using system.collections; public class menu : monobehaviour { public void changescene(string scenename) { scenemanager.loadscene("scenename"); } }
you can't plug in menu
script left slot.
you have attache menu
gameobject plug gameobject
left slot.you able chose script , function send event on right.
the image below shows wrong way this(this how doing it):
the correct way it:
you can code:
public class menu : monobehaviour { public button playbutton; void start() { //add button event playbutton.onclick.addlistener(() => buttoncallback(playbutton)); } public void changescene(string scenename) { scenemanager.loadscene("scenename"); } private void buttoncallback(button buttonpressed) { if (buttonpressed == playbutton) { changescene("myscene"); } } }
Comments
Post a Comment