GUI Text Blinking came up with one error.

The error came up saying “Assets/Ghost/Scripts/WarningText.cs(13,17): error CS0031: Constant value 1’ cannot be converted to abool’”

Here’s the code:

using UnityEngine;
using System.Collections;

public class WarningText : MonoBehaviour {
	
	private bool textBlinking = false;
	
	void Start() {
		blinking();
	}
	
	IEnumerator blinking() {
		while(textBlinking) {
			textBlinking = true;
			yield return new WaitForSeconds(.5);
			textBlinking = false;
			yield return new WaitForSeconds(.5);
		}
	}
	
	void OnGUI() {
		GUIStyle style = new GUIStyle("label");
		style.fontSize = 40;
		GUI.color = Color.red;
		GUI.Label(new Rect(0, 0, Screen.width/2, Screen.height/2),
			"STAY AWAY FROM GHOSTS!", style);
	}
}

http://docs.unity3d.com/Documentation/ScriptReference/index.Coroutines_26_Yield.html

The function needs to return IEnumerator rather than void.

“while (1)” isn’t a valid line

the while statement is looking for a true or false, thus it is saying you cannot convert a constant (1) to a true or false. 1 is always 1.

you may be better having a boolean variable called isBlinking and set that to true or false, then you can use while(isBlinking) or while(!isBlinking) depending on what you want.

incidentally, there are better ways of doing this, look up “delays”

Here :

using UnityEngine;
using System.Collections;
 
public class WarningText : MonoBehaviour {
GUIStyle style = new GUIStyle();
private bool textBlinking = false;
Rect rect;
float delay = 0.2f;
float currentDelay;



void Start() {

   rect = new Rect(0, 0, Screen.width/2, Screen.height/2);
   style.fontSize = 40;
   GUI.color = Color.red;
currentDelay = Time.time + delay;
}
 
void Update()
{
	if (Time.time > currentDelay)
	{
	currentDelay = Time.time + delay;
		if(textBlinking)
		{
		textBlinking = false;
		}
		else if(!textBlinking)
		{
		textBlinking = true;
		}
	}

}

void OnGUI() 
{
    if(textBlinking)
    {
        GUI.Label(rect,"STAY AWAY FROM GHOSTS!", style);
    }
}

}

Hopefully I did not miss anything…:

using UnityEngine;
using System.Collections;
 
public class WarningText : MonoBehaviour {
GUIStyle style = new GUIStyle();
private bool textBlinking = false;
Rect rect;
void Start() {
   rect = new Rect(0, 0, Screen.width/2, Screen.height/2);
   style.fontSize = 40;
   
   StartCoroutine(blinking());
}
 
IEnumerator blinking() {
float timer = 0f;
float endTimer = 0f;
while(endTimer < 5f){
	while(timer < 1f) {
	   	timer += Time.deltaTime;
	    yield return null; 
	}
	endTimer += timer; 
	timer = 0f;
	textBlinking = !textBlinking;
	yield return null; 
}
textBlinking = false;
 }
 
void OnGUI() {

    if(textBlinking){
         GUI.color = Color.red;
         GUI.Label(rect,"STAY AWAY FROM GHOSTS!", style); 
    }
}
}

EDIT: Blinking method is reviewed and working.

while(endTimer < 5f){

defines how long the message displays

while(timer < 1f)

defines how long the message lasts on and off screen