(Unity) Unity implements the ability to click the Android Back button to return to the previous page similar to the Android native project

Source: Internet
Author: User

This chapter bloggers and everyone discuss how Unity implements similar Android native programs, and clicking the Android Back button enables you to return to the previous page.

1. Define a generic type to respond to the Android return button

Public Static list<GameObject> list;

Public                     Gameobject AddPanel; //Add Home Page

2, in the Start method will press the first page into the stack

List = new list<GameObject> (5);

//Press the page into the stack

List. ADD (AddPanel);

3, in the Update method in real-time monitoring the return button of the Android phone trigger situation

if (Input.getkeydown (Keycode.escape))

{

Androidback ();

}

4, from one page to another page to press the page name into the stack

Public Static void androidnext (gameobject Nextgo)

{

List. ADD (NEXTGO);

Nguitools.setactive (list[list. Count-2], false);

Nguitools.setactive (list[list. Count-1], true);

}

5. When you click the Back button on a page in an Android phone, the page name pops up on the stack.

Public Static void Androidback ()

{

if (list. Count > 1)

{

Nguitools.setactive (list[list. Count-1], false);

Nguitools.setactive (list[list. Count-2], true);

List. RemoveAt (list. COUNT-1);

}

Else

{

Application.loadlevel (0);

List. RemoveAt (0);

}

}

(Unity) Unity implements the ability to click the Android Back button to return to the previous page similar to the Android native project

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.