• 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 Orloffyeah · Mar 28, 2013 at 10:57 PM · guimoveanimateblinking

Make a "Blinking/Moving/Animating" GUI

Hi, what I mean by "blinking" is that I want that a GUI button appears on the screen showing the spacebar being pressed and unpressed, showing that the player has to tap the spacebar very fast. How could I make it so that a GUI change itself with other so that an "animation" occurs?

Comment
Add comment · Show 1
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 ByteSheep · Mar 28, 2013 at 11:05 PM 0
Share

Call a function that toggles a boolean variable after a certain amount of seconds and display the GUI depending on the variable state. e.g.:

 if(displayGUI)
 {
   GUI.Button(....);
 }

You can use InvokeRepeating to call a function at a set interval

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by Professor Snake · Mar 29, 2013 at 06:35 AM

You can use a MovieTexture in a GUI.DrawTexture function and call myTexture.Play() to make it play. Alternatively, you can have an array with all the keyframes and use something like this

 var keyframePointer:int=0;
 var delay:float=0.1;
 var timePointer:float=0;
 var myKeyframes:Texture2D[];
 function OnGUI(){
 if(showTexture){
 GUI.DrawTexture(myRect,myKeyframes[keyframePointer];
  if(timePointer<Time.time){
     keyframePointer++;
     timePointer=Time.time+delay;
   }
 }
 }

Comment
Add comment · Show 5 · 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 Professor Snake · Mar 29, 2013 at 06:37 AM 0
Share

I apologise for not being able to format the code properly. Doing so on mobile is a pain.

avatar image Orloffyeah · Mar 29, 2013 at 05:40 PM 0
Share

Thanks for the quick response, but in a part of the code you worte %, is i used for something or is it a mistake?

avatar image Professor Snake · Mar 30, 2013 at 04:32 AM 0
Share

It is the operator for the remainder of the division (although now that you mention it, $$anonymous$$athf.Floor(Time.time-startTime+1) might be better than just (Time.time-startTime)). The idea behind it is this: We want to have a number that keeps increasing until it reaches array.length-1, after which point it should return to 0. Let's assume that your array has 5 keyframes, and you call the ShowTexture function when Time.time=10 (whick makes startTime=10). At that time, (Time.time-startTime+1) will have a value of 1, which makes the remainder of the division 1/5 be 1. In the next second, it will be 2 etc etc. When Time.time reaches 14, (Time.time-startTime+1) will have a value of 5. 5%5 equals 0. So, (Time.time-startTime+1) will go up to 5 and return to 0 every 5 frames. The +1 there is added to prevent a division with 0.

avatar image Professor Snake · Mar 30, 2013 at 04:39 AM 0
Share

Of course, this is a somewhat complex way of incrementing the value. Here is a more simple way that also has a delay variable:

 var keyframePointer:int=0;
 var delay:float=0.1;
 var timePointer:float=0;
 var my$$anonymous$$eyframes:Tezture2D[];
 function OnGUI(){
 if(showTexture){
 GUI.DrawTexture(myRect,my$$anonymous$$eyframes[keyframePointer];
  if(timePointer<Time.time){
     keyframePointer++;
     timePointer=Time.time+delay;
   }
 }
 }

Edit: Updated my answer with this piece of code ins$$anonymous$$d of the other one.

avatar image Orloffyeah · Mar 30, 2013 at 03:33 PM 0
Share

Thanks for all the time that you put into explaining this to me, I already tested it and it works! I really appreciate that you explained every bit and in a very detailed way. Thanks once again and have a nice day.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

Moving gui texture 1 Answer

How do I make an object move when I click a GUI button? I want the object move upward. 2 Answers

Building an Accordion 0 Answers

GUIManager, SpriteUI and Animate 1 Answer

Editing buttons created in 'for' loop. 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