I haven't written a blog for nearly a week, mainly because I went to learn C #, and I found that I didn't learn the most basic things well, so I just supplemented it a little ~~~
Next let's take a basic look at the scenario switching, which is similar to the activity switching in Android. Let's take a look.
The following are required for switchover: 1. Two or more scenarios; 2. Application. loadlevel (x) // X can be the scenario name or scenario number. 3. An event is triggered.
Scenario menu
Scenario Yaya
Scenario yaya1
Paste the followingCodeNow:
Using unityengine; using system. collections; Public Class Menu: monobehaviour {bool flag; void start () {dontdestroyonload (this); // when switching a scenario, the following code is not revoked
Flag = true;} void Update () {If (input. getkeydown (keycode. space) {If (FLAG) {flag = false;} else {flag = true ;}} void ongui () {If (! Flag) {return;} If (GUI. button (New rect (screen. width/2-50, screen. height/2-30, 40, 60), "yaya1") {application. loadlevel (1);} If (GUI. button (New rect (screen. width/2, screen. height/2-30, 40, 60), "yaya2") {application. loadlevel (2);} If (GUI. button (New rect (screen. width/2 + 50, screen. height/2-30, 40, 60), "quit") {application. quit ();}}}
Bind the above Code to the first scenario (menu;
Let's explain the code.
Dontdestroyonload (this); // when switching a scenario, the following code is not revoked, rather than the game object in the scenario.
Application. Quit (); exit