Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Mar 06, 2017 at 09:54 PM by sPYfromFranik for the following reason:

Figured out myself. Might be a Unity 5 bug, actually.

avatar image
0
Question by sPYfromFranik · Mar 09, 2017 at 10:26 AM · androidcanvasdisableenable

Can't enable/disable canvas on Android device

I'm trying to create a pause menu. When I press the escape button (back button on Android device) the canvas with menu should activate. When I do this on PC in Unity 5 - it works great. When I build and run this app on my Android phone - it doesn't works. I've tried two methods. The first one is:

 public class GameController : MonoBehaviour
 {
     private Canvas pauseMenu;
     private void Start()
     {
         GameObject pauseMenuobject = GameObject.FindWithTag("PauseMenu");
         if (pauseMenuobject != null)
             pauseMenu = pauseMenuobject.GetComponent<Canvas>();
         if (pauseMenuobject == null)
             Debug.Log("Cannot find Canvas");
         pauseMenu.gameObject.SetActive(false);
     }
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.Escape))
             if (!pauseMenu.gameObject.activeInHierarchy)
                 pauseMenu.gameObject.SetActive(true);
             else if (pauseMenu.gameObject.activeInHierarchy)
                 pauseMenu.gameObject.SetActive(false);
     }
 }

And the other one is:

 public class GameController : MonoBehaviour
 {
     private Canvas pauseMenu;
     private void Start()
     {
         GameObject pauseMenuobject = GameObject.FindWithTag("PauseMenu");
         if (pauseMenuobject != null)
             pauseMenu = pauseMenuobject.GetComponent<Canvas>();
         if (pauseMenuobject == null)
             Debug.Log("Cannot find Canvas");
         pauseMenu.enabled = false;
     }
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.Escape)){
             if (pauseMenu.enabled == false)
                 pauseMenu.enabled = true;
             else if (pauseMenu.enabled == true)
                 pauseMenu.enabled = false;
     }
 }

Both work in the Unity 5, but when I build and run it on Android - it doesn't works. Even more, on android it doesn't even disables the canvas in void Start() nor it passes the if () in the void Update().

What am I doing wrong? Is this type of disabling/enabling works only in Unity 5 and does not works when you build it? Or is it because I launch it on the Android? What should I do? Thanks in advance.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sPYfromFranik · Mar 06, 2017 at 09:52 PM 0
Share

Somehow, reloading the Unity 5 - fixed this problem. I'm not sure, but I guess it has something to do with tags. When I was making a tag for my menu canvas I made a mistake, then deleted this tag, and created a new one. When I deleted the first one I had a message "There are removed tags. They will be removed from this list the next time the project is loaded".

Though, further on I used only the correct, second one, tag, somehow this deleted tag seems to effect the app, when it was build and launched on Android device.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Activate one canvas and deactivating the other. 1 Answer

Enable and disabled parent contraint with c# 1 Answer

Text smaller on Android 0 Answers

Android Unity App With Facebook Integration - Canvas Problems 0 Answers

How to overlap 2 or more UI Elements 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges