Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by mmangual_83 · Jul 09, 2014 at 06:13 PM · c#

How to toggle the visibility of GUI Button

Hello, I am working with NGUI and I wanted to know how do I make a GUI button game object (and its children)invisible when I start the game and then visible again.

I thought I had to de-activate the GameObject, but I read that once you do that then there is no way to activate it again (not without some complicated hard-coding). I noticed that the NGUI button has a script attached to it called UISprtite and after much research I found out that it handles visibility. Eureka!

So my question is: "what do I need to do in order to have my game object button and its children to disappear?"

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Zephire · Jul 09, 2014 at 07:30 PM

If you're working with NGUI and the only thing you need to do is making a specific button visible and unvisible on certain events / commands you could use

 NGUITools.SetActive(buttonGameObject, false)
 
 //or
 
 NGUITools.SetActive(buttonGameObject, true)


If something more complicated is needed feel free to elaborate. But that's what I got from your question.

Cheers, Z

Comment
Add comment · 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
0

Answer by dogtorque · Jul 09, 2014 at 07:11 PM

here is page that gives you info about the pause menu. Click here

Comment
Add comment · Show 1 · 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 mmangual_83 · Jul 09, 2014 at 07:18 PM 0
Share

@dogtorque I see what its doing, but its a bit different than what I am doing.

avatar image
0

Answer by hristo991 · Jul 09, 2014 at 07:39 PM

here is a simple way to do it, using boolean in javascript: var toggle : boolean;

 function OnGUI () {
  if(toggle) //you can use toggle==true as well, but this way it's shorter
  {
   if(GUI.Button(Rect(0,0,250,30), "Button")) //draw your button
   {
    //do something
   }
  }
 }

However, for a game object its a bit more complicated...

first you create a script that has a boolean and another variable that contains the gameobject:

 var toggle : boolean;
 var buttonObject : GameObject;

then, you make an empty gameobject and add the script to it. This gameobject should never be destroyed or disabled, because it contains the "link" to the button.

from there you can access the script and it's "toggle" variable and enable/disable the button you want :)

Comment
Add comment · Show 1 · 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 Zephire · Jul 09, 2014 at 07:44 PM 0
Share

Very true option @hristo991, but mmangual_83 is making use of the NGUI asset. So setting things up the way he's looking for shouldn't need the additional coding.

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.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

A node in a childnode? 1 Answer

Beam of light for flashlight coding issue 2 Answers

Unity Pro Navigation AI c# animations and stopping? 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