I am trying to get timer to remove GUI text… I have gotten this far and most of it works but I cannot get the timer to actually count down and remove text.
static var textOn : boolean = false;
static var textContent : String;
private var textTimer:float ;
function Start()
{
textTimer = 0.0;
textOn = false;
guiText.text = "";
}
function Update () {
if(textOn)
{
guiText.enabled = true;
guiText.text = textContent;
var textTimer:float -= 1 * Time.deltaTime;
}
var textTimer:float = 6.0;
if(textTimer >= 5.0 )
{
textOn = false;
guiText.enabled = false;
textTimer = 0.0;
}
}
Seems like you might have some local vs global property issues (scope) as well as others.
try this ( I don’t use JS so there might be some issue)
var startTimer:float = 0.0;
var textOffTime:float = 6.0;
function OnEnable() {
startTimer = Time.time;
textOn = true;
guiText.text = "";
}
function Update () {
if(textOn)
{
guiText.enabled = true;
guiText.text = textContent;
}
if(Time.time - startTimer >= textOffTime )
{
textOn = false;
guiText.enabled = false;
}
}
Actually it was this line:
var textTimer:float -= 1 * Time.deltaTime;
It should actually read:
var textTimer += Time.deltaTime;
Took a bunch of trial and error but I figured it out. Thanks for the attempt though!