Switching between Android + unity game development basic scenarios

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.