Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Divya Talluri 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.
-
NGUITools.SetActive(buttonGameObject, false).
-
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 :(
-
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
-
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?
-
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.
-
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 :)
-
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 :(
-
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.
-
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.
-
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.
-
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?
-
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.
-
MyBtn is of type UIButton, the instance is being destroyed while moving to another scene.
-
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.
-
Philip has it right. If you look at the two functions that allow you to add and retrieve items from the tracker, they are always expected to be of type GameObject.
You can, of course, write your own classes that have a different expected type for the hashtable. It would be inadvisable to try to implement a hashtable tracker that stores any type, which you then cast on retrieval... mostly because as a human you'd end up forgetting details and be forever mis-using return values and troubleshooting the resulting bugs.
-
I am accessing like MyBtn.gameobject in the script.Everything is fine when I am in the same Scene, but when moved from this scene to another scene,comes back to this scene getting that error.
As when moved to another scene instances are destroyed(may be this is the reason).I have used DontDestroyOnLoad() method on this gameobject, still it is giving the same errors
1.MyBtn Cannot add item to GlobalGameObjectTracker hashtable.
2.MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
NGUITools.SetActive (UnityEngine.GameObject go, Boolean state) (at Assets/NGUI/Scripts/Internal/NGUITools.cs:540)