Author Topic: Making UIButton Invisible  (Read 14675 times)

Divya Talluri

  • Guest
Making UIButton Invisible
« on: October 30, 2012, 08:14:10 AM »
Hi Aren,

           How to make UIButton invisible? May be this is simple question, as I am new to NGUI struggling with this.I just want to make Button not included in UI,but whenever needed i want to make it visible and invisible so i cant use  nguitools.destroy method becoz it makes uibutton permanantly removed from UI.

Thanks in advance.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Making UIButton Invisible
« Reply #1 on: October 30, 2012, 08:14:44 AM »
NGUITools.SetActive(buttonGameObject, false).

Divya Talluri

  • Guest
Re: Making UIButton Invisible
« Reply #2 on: October 30, 2012, 08:44:15 AM »
ty for the fast reply, it worked while making invisible but when i want to make it visible,for making visible i am getting button game object,then it shows error like nullobjreference  :(

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Making UIButton Invisible
« Reply #3 on: October 30, 2012, 11:00:59 AM »
You have to create a GameObject variable and store a reference to the button you are disabling.  Once disabled, the "Find" functions of Unity cannot find those game objects.  For performance reasons you should be doing this anyhow.

I've posted up example code for tracking gameobjects here:  http://www.tasharen.com/forum/index.php?topic=2171.0
« Last Edit: October 30, 2012, 11:39:28 AM by JRoch »

Divya Talluri

  • Guest
Re: Making UIButton Invisible
« Reply #4 on: October 31, 2012, 12:02:29 AM »
Hi JRoch,

ty for the helping me, but i have many buttons in the UI. Shall i attach the script to each button? Is that the correct way to do?

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Making UIButton Invisible
« Reply #5 on: October 31, 2012, 01:49:08 AM »
Either that, or write a script that walks the hierarchy on Awake() and stores handles to every object before you disable anything.  This means you'll want to have your panel start out of camera view (say -5000 X or something) and finish initialization with disabling any controls you want, perhaps even the parent panel, and then moving the panel via transform to the location you really want it.

There are a *lot* of different ways to approach object management.  You might think about creating a new test project, or a test scene, and then doing a bunch of experimentation before you spend a lot of time modifying your "live" project or scene.

Divya Talluri

  • Guest
Re: Making UIButton Invisible
« Reply #6 on: October 31, 2012, 01:54:04 AM »
Better I will go with the normal approach, becoz I have no time to do experiments now.But I will definetly try the new one when i am free.
Thank you so much.it helped a lot and saved my time :)

Divya Talluri

  • Guest
Re: Making UIButton Invisible
« Reply #7 on: November 01, 2012, 01:25:09 AM »
hey I have another question on this..How to make this duplicate UIButton object disable or enable? I tried like typecasting it to UiButton but  gives error convert `UnityEngine.GameObject' to `UIButton'.Help me with this :(
« Last Edit: November 01, 2012, 01:29:07 AM by Divya Talluri »

Divya Talluri

  • Guest
Re: Making UIButton Invisible
« Reply #8 on: November 01, 2012, 03:47:04 AM »
And another question too, how to set all UIButton properties to the duplicate game object? I want to disable it when on clicked and set it default color when clicked on another button. Please give sample code how to do this, becoz when i am trying to set the disable color  and default color they are not working, it looks same when after clicking.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Making UIButton Invisible
« Reply #9 on: November 01, 2012, 09:27:24 AM »
A game object can't be cast to a component type. You need to use GetComponent on it. Consult Unity's documentation for more information.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Making UIButton Invisible
« Reply #10 on: November 01, 2012, 12:37:34 PM »
Aren's advice is about as much as I can help as well.  It's clear you are a fairly novice programmer with Unity, so you need to start with basics and educate yourself so you understand the code you are working with.

Divya Talluri

  • Guest
Re: Making UIButton Invisible
« Reply #11 on: November 02, 2012, 05:05:55 AM »
thank u guys for the help. I learned a lot from forums. Everything is working fine now except one issue.
The issue is, as spoke about the GlobalGameObjectTrackerClass, when i am loading from another scene to this scene(where i have used the tracker class), i am getting error "MyBtn Cannot add item to GlobalGameObjectTracker hashtable."
Can u guys please suggest what to do with this?

PhilipC

  • Guest
Re: Making UIButton Invisible
« Reply #12 on: November 02, 2012, 05:52:13 AM »
What is the type of MyBtn? Is it a GameObject or a UIButton or...? because my guess is that you are trying to add a invalid type to the GlobalGameObjectTracker.

My other thought would be that the hastable already has MyBtn and its not liking the duplicate entry.

Divya Talluri

  • Guest
Re: Making UIButton Invisible
« Reply #13 on: November 02, 2012, 06:36:56 AM »
MyBtn is of type UIButton, the instance is being destroyed while moving to another scene.

PhilipC

  • Guest
Re: Making UIButton Invisible
« Reply #14 on: November 02, 2012, 08:32:03 AM »
Ok so my next question would be, if MyBtn is of type UIButton are you trying to add MyBtn.gameobject to the hashtable or just MyBtn. I dont think (from what i understand by the name of the type) GlobalGameObjectTracker will only take GameObjects not UIButtons.