HELP!! unexpected token: If
this is my code:
#pragma strict
var store = false;
static var click = 0;
var money = 500;
function Start ()
{
}
function Update ()
{
if (Input.GetKeyDown (KeyCode.Escape))
{
store = true;
}
if (store == true)
{
storeopen();
}
}
function storeopen ()
{
if (GUI.Button(Rect(10,10,50,50),"Seeder"));
{
if (money == 100);
{
money : 100};
yield WaitForSeconds (2);
money = 900;
}
dont know whats wrong any help will be good :)
Doesn't really matter the fix. You're trying to call an OnGUI function outside OnGUI which will throw you an error OnGUI can't be used as Corutine.
What are you trying to achieve?
What this line supposed to do
money : 100
?You already have same question asked here . Please don't post same question twice.
Something like this should solve your problem :
#pragma strict
var store = false;
static var click = 0;
var money = 500;
function Update () {
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Escape))
{
store = !store;
}
}
function OnGUI () {
if (store){
storeOpen();
}
}
function storeOpen(){
if (GUILayout.Button("Seeder"))
{
if (money == 100)
{
money = 100;
}
yield WaitForSeconds (2);
money = 900;
}
}
But I still don't understand the line :
if (money == 100){
money = 100; //or money : 100;
}
money : 100;
her it is supposed to say: money -= 100;
but i got an error from that saying that there should be a ":" sign ins$$anonymous$$d
But no worries!! i fixed the code by using this ins$$anonymous$$d:
pragma strict
ar store = false; static var click = 0; var money = 500; function Start () {
}
function OnGUI() { if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Escape)) { store = true; } if (store == true) { storeopen(); } }
function storeopen () { if (GUI.Button(Rect(10,10,50,50),"Seeder")) { if (money == 100) { money -= 100;}
yield WaitForSeconds (2); money = 900; }
}
Answer by Ryzokuken · Sep 13, 2015 at 03:35 PM
The fix:
if (GUI.Button(Rect(10,10,50,50),"Seeder"));
if (money == 100);
Remove the semicolons after the If. That should remove this error.
BTW, @Positive7 is quite right. OnGUI()
functions cannot be called from outside OnGUI()
. Do not worry. Replace the Update()
with OnGUI()
because IMO, OnGUI is basically called more times than Update is.
i fixed it with your help and the other guys too! thanks! i didnt make it exactly as you said because it screwed up some other things but i managed to get it working!! thank you! + 1 point to you!
i used this code ins$$anonymous$$d:
pragma strict
ar store = false; static var click = 0; var money = 500; function Start () {
}
function OnGUI() { if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Escape)) { store = true; } if (store == true) { storeopen(); } }
function storeopen () { if (GUI.Button(Rect(10,10,50,50),"Seeder")) { if (money == 100) { money -= 100;}
yield WaitForSeconds (2); money = 900; }
}
Your answer
Follow this Question
Related Questions
Unexpected token: if HELP 1 Answer
Disable a script from another script 3 Answers
error CS1525: Unexpected symbol `' 2 Answers
How to disable any type of component? 2 Answers
BCE0043 unexpected token: ")"? 1 Answer