• 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 /
avatar image
Question by jurgjurg · Feb 11, 2015 at 10:26 AM · uisetactive4.6virtualoverride

.setactive not working? on new unity ui 4.6

The ui stays on the screen even after this code: this invokes a hideGUI() method

 if (currentPlayerIndex < amountPlayers - 1) {
 
                         players[currentPlayerIndex].hideGUI();
                         currentPlayerIndex++;
                         players[currentPlayerIndex].showGUI();
                         
                 } else {
             players[currentPlayerIndex].hideGUI();
             currentPlayerIndex = 0;
             players[currentPlayerIndex].showGUI();
         }

this is the thing from a monobehaviour class:

    public virtual void hideGUI(){
     
             panelendturnButton.SetActive (false);
             
         }

this is from the script on the game object that derives from the above class:

 public override void hideGUI(){
         
         base.hideGUI ();
 
         Debug.Log("user hide");
         
     }


the debug.log in the override goes off, but the gui still stays on the screen :S

Info about the hierarchy:

I have a canvas, with attached to it a panel. This panel has a button attached to it. Trying to make the panel referenced in the inspector as panelendturnButton didn't work, so i made a prefab of the canvas which allowed me to make the prefab panel as a GameObject reference for the script.

So basically I have a canvas and it's prefab is referenced in the inspector, maybe this is the problem? but trying to reference the panel directly from the hierarchy didn't work :S

also tried instantiating the canvas from the prefab, made no difference

Comment
NirielNabokov
plus5keen

People who like this

2 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 Joyrider · Feb 11, 2015 at 10:27 AM 0
Share

What is you GUI hierarchy, and what is panelendturnButton exactly?

Are you sure you are not just deactivating the button object and not the graphical representation?

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Mmmpies · Feb 11, 2015 at 11:30 AM

Working on a guess that panelendturnButton is a UI Button can you try

 panelendturnButton.gameObject.SetActive(false);

You need tp reference the gameObject to set active.

Comment
jurgjurg
thenipponese
plus5keen

People who like this

3 Show 5 · Share
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 jurgjurg · Feb 12, 2015 at 01:49 PM 0
Share

tried this didn't work

edited the post on info of the hierarchy

avatar image Mmmpies · Feb 12, 2015 at 02:02 PM 0
Share

Is that a ui Button? And are you trying to hide the entire ui or just the panelendturnButton?

avatar image jurgjurg · Feb 12, 2015 at 02:39 PM 0
Share

It is indeed a UI button, but i'm trying to hide the panel which only has the button attached to it, might be worth reading the edited part of the post

avatar image Mmmpies · Feb 12, 2015 at 03:34 PM 0
Share

your update hadn't appeared. Just how Answers works, it may have been in Moderation or just slow appearing. You might also want to consider not being so short with people who are helping you for free, the vast majority on here are not employees of Unity, just trying to help others out.

Also if someone gives you a correct answer, tick it, I note you've asked 3 questions and none have been ticked, yeah I know this isn't answered yet but get a reputation for not ticking and some people won't help you.

So what you want is something like this:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 // then, in your class, create a public Canvas
 public Canvas myCanvas;
 
 
 public void HideCanvas()
 {
     myCanvas.gameObject.SetActive(false);
 }
 
 public void ShowCanvas()
 {
     myCanvas.gameObject.SetActive(true);
 }

Drag the script onto the canvas and then highligh the canvas. Drag the canvas onto the empty slot in the script attached to the canvase.

Highlight the button click + in the onClick section. Drag the Canvas with the script onto it and from the dropdown select myScriptName -> HideCanvas.

Typed blind into the editor so watch for typos.

avatar image jurgjurg · Feb 14, 2015 at 12:34 PM 0
Share

Thanks a lot, adding a script to the Canvas itself made it so I could add the reference from the hierarchy itself

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

4.6 UI Text rect does not expand automatically 2 Answers

Unity 4.6 button movement problem 1 Answer

[4.6 - UI] Keep aspect ratio 2 Answers

Unity UI Button states 1 Answer

Can't add reference resolution on Canvas 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