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 Sillan · Feb 13, 2013 at 11:17 AM · guiflashblinkingblink

Flashing/Blinking GUI

Hey guys, I was just wondering if anyone knew how to write a script that you could attach to a gui texture to make it blink or flash on and off continuously. Thanks so much, Johnny :D

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
2
Best Answer

Answer by moghes · Feb 13, 2013 at 12:02 PM

since OnGUI function is a function that is being called by the engine just like the Update function. this must be something easy to acheive.

Try this:

 private var blink = false;
 private var counter:int = 0;
 private var blinkSpeed:int = 10;
 public var yourGUITexture:GUITexture;
 
 function Update()
 {
     if(counter == blinkSpeed)
     {
         blink = true;
         counter = 0;
     } 
     else
         blink = false;
     
     counter++;
 }
 
 function OnGUI()
 {
      if(blink)
         yourGUITexture.guiTexture.enabled = true;
      else 
         yourGUITexture.guiTexture.enabled = false;
 }

Now attach this script to an empty game object(or whatever) in your scene, and drag you GUITexture to add to the public var "yourGUITexture". I just tried , working :)

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 Sillan · Feb 13, 2013 at 12:20 PM 0
Share

Perfect, Thankyou so so much :D You're a Genius !!!

avatar image moghes · Feb 13, 2013 at 12:28 PM 0
Share

If that was what you needed, please tick as true, might be helpful for others

avatar image
0

Answer by Sillan · Feb 13, 2013 at 12:46 PM

Ok sure, Sorry. I'm new to these forums and I don't have much experience.Thanks again though for your help.

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 GluedBrain · Jan 11, 2015 at 07:05 AM

You can use the Coroutines and new Unity 4.6 GUI to achieve this very easily. Check this article here

Blinking Text - TGC

If you just need the code, here you go

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 
 public class FlashingTextScript : MonoBehaviour {
 
  Text flashingText;
 
  void Start(){
   //get the Text component
   flashingText = GetComponent<Text>();
   //Call coroutine BlinkText on Start
   StartCoroutine(BlinkText());
  }
  
  //function to blink the text 
  public IEnumerator BlinkText(){
   //blink it forever. You can set a terminating condition depending upon your requirement
   while(true){
    //set the Text's text to blank
    flashingText.text= "";
    //display blank text for 0.5 seconds
    yield return new WaitForSeconds(.5f);
    //display “I AM FLASHING TEXT” for the next 0.5 seconds
    flashingText.text= "I AM FLASHING TEXT!";
    yield return new WaitForSeconds(.5f);
   }
  }
  
 }
 

P.S: Even though it seems to be an infinite loop which is generally considered as a bad programming practice, in this case it works quite well as the MonoBehaviour will be destroyed once the object is destroyed. Also, if you dont need it to flash forever, you can add a terminating condition based on your requirements.

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

11 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

Related Questions

GUI buttons glow/flash/fade between textures 0 Answers

how Can I make a UI Image Blink On And Off 5 Answers

how to "blink" more often? 2 Answers

Separate UI in Flash - examples? 2 Answers

GUI Text Blinking came up with one error. 3 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