How do you make a blinking GUI?
Bikebreck
How do you make a blinking GUI?
Bikebreck
var instanceMet : boolean = true;
static var flashTexture : boolean = false;
InvokeRepeating ("checkGUI", 0.001, 0.30);
function flashGUI () {
yield WaitForSeconds(0.075);
guiTexture.color.a = 0.125;
yield WaitForSeconds(0.075);
guiTexture.color.a = 0.250;
yield WaitForSeconds(0.075);
guiTexture.color.a = 0.375;
yield WaitForSeconds(0.075);
guiTexture.color.a = 0.250;
}
function checkGUI() {
if (instanceMet) {
flashGUI();
flashTexture = true;
} else {
flashTexture = false;
guiTexture.color.a = 0.375;
}
}
Not very conventional I know, but it does the job.
This particular code is untested by the way.
EDIT: Yeah, sorry, I was thinking GUITexture there for some deranged reason.
/* Flashing button example */
function OnGUI () {
if (Time.time % 2 < 1) {
if (GUI.Button (Rect (10,10,200,20), "Meet the flashing button")) {
print ("You clicked me!");
}
}
}
found on this page, form unity Unity - Manual: IMGUI Basics
Thanks for the help i did not see that it the help.
Here’s one way of doing it:
using UnityEngine;
using System.Collections;
public class MyBlinkingThingy : MonoBehaviour
{
public Rect m_LabelRect = new Rect (0, 0, 200, 20);
public string m_Label = "Blink!";
public float m_BlinkFrequency = 2.0f;
private bool m_Show = true;
IEnumerator Start ()
{
// Initialize stuff here
while (Application.isPlaying)
{
yield return new WaitForSeconds (1.0f / m_BlinkFrequency);
m_Show = !m_Show;
}
}
void OnGUI ()
{
if (!m_Show)
{
GUI.color = new Color (1, 1, 1, 0);
}
GUI.Label (m_LabelRect, m_Label);
GUI.color = Color.white;
}
}