x


HELP with scripting where GUI is involved

I have a section of code set up which is making the text appear, but it is appearing as soon as i press play rather than when the animation is triggered, hoping someone can help me sort this problem out, ill post my code below.

Thanks in advance for any help offered.

displayMessage = false;

function OnTriggerEnter (Player : Collider) 
{
     animation.Play("Take 001");
     displayMessage = true;
     yield WaitForSeconds(3);
     displayMessage = false;
}

function OnGUI ( )
{
     if ( "displayMessage" ) 
     {
         GUI.Label(new Rect(Screen.width /2.5, Screen.height / 2, 200, 200), "You received 5gp");
     }
}
more ▼

asked Apr 15 '11 at 12:47 AM

Christopher Travis gravatar image

Christopher Travis
17 6 7 9

Just my 2 cents... You should learn scripting if you really want to pursue this... Obviously, if this is for a school project, then you should be trying to LEARN something, rather than script kiddy'ing all day and having people do your whole project for you... If you don't want to make a game, then don't make a game... If you want to take the time to learn to make a game, than take the time... What you're asking is a very stupid and ignorant question that anyone with any brain of programming knowledge could answer...

Apr 15 '11 at 02:21 AM Justin Warner
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

At the top where you say:

displayMessage = false;

it should say:

var displayMessage = false;

and whereit says:

 if ( "displayMessage" )

it should just say:

if (displayMessage)
more ▼

answered Apr 15 '11 at 12:58 AM

Joshua gravatar image

Joshua
6.4k 19 25 70

thanks joshua that helped solve that problem.

Apr 15 '11 at 01:00 AM Christopher Travis

is there any way to change the size etc of the text that appears on screen? is that done in the code?

Apr 15 '11 at 01:05 AM Christopher Travis

Travis, this site is for helping unity developers when they have a real question, not for asking questions that have already been answered http://answers.unity3d.com/search?q=gui+text+size and are easy to look up http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html

Apr 15 '11 at 01:32 AM Joshua
(comments are locked)
10|3000 characters needed characters left

change if ( "displayMessage" ) to if ( displayMessage )

more ▼

answered Apr 15 '11 at 12:49 AM

marceloroca gravatar image

marceloroca
156 6

ok thanks ive just tried that when i did it though this error occurred.

Assets/NewBehaviourScript.js(13,14): BCE0005: Unknown identifier: 'displayMessage'.

Apr 15 '11 at 12:52 AM Christopher Travis
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5084
x3791
x3689
x553
x313

asked: Apr 15 '11 at 12:47 AM

Seen: 471 times

Last Updated: Apr 15 '11 at 12:47 AM