I'm having a bit of trouble with some Unityscript.
What I want to do is have a GUI message appear when certain objects are touched (then vanish after a time). I think I have it mostly worked out, but the message trips automatically.
My attempted solution is to have a conditional part of the GUI message that only allows it to appear when a boolean is true. Then in a different script that is already tripped when the object is touched, the boolean is set to true, so the script can run, and reset the boolean to false.
However I'm getting a "You can only call GUI functions from inside OnGUI. I'm not sure what that means.
Message code:
youdied.js
static var deathMessageShow : boolean = false;
function OnGUI() {
if(deathMessageShow == true){
if(Time.time >= 5 )
GUI.Box(Rect(200,300,275,150),"You Died");
}
deathMessageShow = false;
}
Other code (truncated):
dead.js
function OnTriggerEnter()
{
//code that resets environment
youdied.deathMessageShow = true;
}
Any suggestions on what is going on, or a better solution would be greatly appreciated.
isDeathMessageShownor so. Everyone would expect adeathMessageto be a string :-) - BergiYouDiedin a public variable instead of using a static variable). Also maybe there's some context missing, butTime.time > 5probably won't do what you want it to. It means that 5 seconds after the game starts you'll no longer show messages (any messages, Time.time is the time since the game started [or you pressed play in the editor, which might make it seem like it's working]) - Selali Adobor