- Home /
Can someone help me with this script please
hi,
I have a script to make a messagebox that appears after a couple of seconds on the screen,
but i get an error ;
Assets/Guimessgage.js(5,7): BCE0077: It is not possible to invoke an expression of type 'int'.
here is the code ;
var WaitSeconds = 10;
function OnGUI () { if (WaitSeconds (10)) { GUI.Box (Rect (10,10,280,30), "To show the mouse press ESC button"); } }
What am i doing wrong.
I also wan't a audioclip to sound when the messagebox appears on the screen.
how do i do that ?
Any help is welcome !
Answer by AngryOldMan · Apr 24, 2011 at 08:54 PM
is this what you are after?
var WaitSeconds : int = 10; var showGUI : boolean = false;
function Start () { WaitFunction(); }
function WaitFunction() { yield WaitforSeconds (WaitSeconds); showGUI = true }
function OnGUI () { if (showGUI == true) { GUI.Box (Rect (10,10,280,30), "To show the mouse press ESC button"); } }
one last question how do i destroy the message after showing ?
if you have a good look at the script and see what everything is doing you will find its blatently clear the way to switch on and off the GUI. If you want to permantly destroy it then have a look at the destory script reference http://unity3d.com/support/documentation/ScriptReference/Object.Destroy.html
Answer by Justin Warner · Apr 24, 2011 at 02:20 PM
OnGUI is ran every single frame. It's equal to Update. Having said this, you can't do a yield/WaitForSeconds (It isn't WaitSeconds) as that stops the frames.
Unless you have a method called WaitSeconds which takes the int you passed in, and then returns true when it's above the time...
So, what I'd do. Have a temp time, make it equal to the System time.
Then have an if statement comparing the current time and that one so like.
var tempTime = System.DateTime.Now.TimeOfDay.Seconds;
function OnGUI()
{
if(tempTime+3 > System.DateTime.Now.TimeOfDay.Seconds)
{
//draw
//play sound
}
}
As for adding sounds: http://unity3d.com/support/documentation/ScriptReference/AudioSource.html
Hope this helps! =)
and also tnx for putting my in de right direction with the audioclip !
one last question how do i destroy the message after showing ?