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 Oxidor · Jul 11, 2013 at 07:09 PM · guitexturedisappear

make GUI texture disappear after a few second ?

Hi i have a problem with a script. i made this:

 var toggleGUI : boolean;
 var textureToDisplay : Texture2D;
  
     function OnTriggerEnter (other : Collider) {
     toggleGUI = true;
     }
  
     function OnTriggerExit (other : Collider) {
     toggleGUI = false;
     }
  
     function OnGUI () {
     if (toggleGUI == true)
     GUI.Label (Rect (500, 200, textureToDisplay.width, textureToDisplay.height),
             textureToDisplay);
     }
     

It display a texture when I'm in a trigger but i want the texture disappear (not destroy) after a few second (like 3sec) but don't know how to do this =s

Tank you in adavance ;)

Comment
Add comment · Show 11
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 brandonsbarber · Jul 11, 2013 at 08:02 PM 0
Share

So you want to have this only occur once? And you want a slow fade?

In other words, the first time you enter the trigger, the image displays but it does not any time after that?

And yeah, please change that answer to a comment.

avatar image Oxidor · Jul 11, 2013 at 08:16 PM 0
Share

Sry, didn't notice the difference between answer and comment :s

I have a door to open. I display a message who explain wich key open the door. So i use the script and it's work (disappear after 3sec) but when i come back near my door ( to close this one for exemple) the guitexture display but the gui texture still display even after the 3 second Sry for my bad english =s

avatar image brandonsbarber · Jul 11, 2013 at 08:23 PM 0
Share

So you only want it to display for 3 seconds if you execute again? Not sure I follow.

avatar image Oxidor · Jul 11, 2013 at 08:25 PM 0
Share

Yes, each time I enter in my trigger i want my GUI texture display just for 3seconds

Your script work fine but just work once (if i come back in trigger, the GUI texture don't disappear)

avatar image brandonsbarber · Jul 11, 2013 at 08:28 PM 0
Share

Check my edit.

Show more comments

1 Reply

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

Answer by brandonsbarber · Jul 11, 2013 at 07:23 PM

Well, first off, since toggleGUI is already a boolean, you do not need to compare it to true or false in OnGUI. Instead, you only need to put:

 if(toggleGUI)

That aside, we come down to your issue. Instead of simply toggling toggleGUI, you can use

 yield WaitForSeconds(3.0);
 toggleGUI = false;

This way, you will pause the function until it is toggled.

EDIT:

If you want the message to only display for 3 seconds, put the above script just after you set toggleGUI to true. And remove the OnTriggerExit

For more information, check out the documentation here

Comment
Add comment · Show 2 · 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 Oxidor · Jul 11, 2013 at 07:57 PM 0
Share

that work nice, thank you !! But that work just one time if i come back on my trigger, the GUI textrue still display. How can i fixe this? And is it possible ton fade out slowly? (easy way not hard code ^^) Thx in adavance

avatar image Oxidor · Jul 11, 2013 at 08:56 PM 0
Share

if someone need this kind of script, it's the final script:

 var toggleGUI : boolean;
 var textureToDisplay : Texture2D;
  
     function OnTriggerEnter (other : Collider)
 {
     toggleGUI = true;
     yield WaitForSeconds(2.0);
     toggleGUI = false;
 }
     
     function OnGUI () {
     if (toggleGUI)
     GUI.Label (Rect (500, 200, textureToDisplay.width, textureToDisplay.height),
             textureToDisplay);
     }

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

18 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

Related Questions

Guitexture appear/disappear 1 Answer

GUI Textures disappearing (on buttons) 1 Answer

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

GUITexture disappears in build 0 Answers

pickup count on GUI 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