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 Confused · Apr 19, 2011 at 09:12 AM · guialphaboxdisappearappear

Make GUI box appear and disappear

Very newbie question. I'm trying to make a GUI box appear when I mouse over an object and disappear when the mouse is no longer on the object. I've been trying to do this by changing the alpha of the GUI box (though I feel like there may be a simpler way, like enabling and disabling the GUI...)

This is what I have so far:

var alpha = float;

function Start(){ alpha = 0;
}

function OnGUI() { GUI.skin.box.wordWrap = true;
GUI.color.a = alpha; GUI.Box(Rect(10,Screen.height/2+115,Screen.width-15,Screen.height/2-120),"text text text"); }

function OnMouseEnter () { alpha = 1; Debug.Log("mouse_enter"); }

function OnMouseExit(){ alpha = 0; Debug.Log("mouse_exit"); }

However my script is not responding to my "alpha" variable. I tried looking for a way to enable and disable the GUI, but there doesn't seem to be an easy way too. Or I'm missing something?

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

2 Replies

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

Answer by efge · Apr 19, 2011 at 09:48 AM

You could set a boolean variable to true or false depending OnMouseEnter/Exit and modify your OnGUI function like this:

function OnGUI() {
  if (guiEnabled) {
    ... //draw GUI stuff
  }
}
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 Confused · Apr 20, 2011 at 11:19 PM 0
Share

YESSSSS thank you so much!! you have no idea what a headache this has been.. very helpful for other scripts too, thank you.

avatar image
0

Answer by robertmathew · Apr 19, 2011 at 09:28 AM

   GUI.backgroundColor = Color(1, 1,1,0);
   GUI.color.a =Mathf.PingPong(Time.time,1);
    GUI.Button(new Rect(Screen.width *(0.2/6.55), Screen.height * (3.9/6.55),Screen.width * (.5/6.55), Screen.height * (.5/6.55)),GUIContent(playtexture,"playgame"));
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

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

No one has followed this question yet.

Related Questions

Can I use a movie texture with alpha as a GUI object? 1 Answer

Distance activated GUI 1 Answer

GUI box not appearing when button is clicked 1 Answer

Why GUI Doesn't appears? 1 Answer

Strange shader behaviour on UI component 0 Answers


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