- Home /
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 :)
If that was what you needed, please tick as true, might be helpful for others
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.
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
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.
Your answer
Follow this Question
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