hi im trying to follow a tutorial about javascripting in unity
heres the code that isn’t working
var mouseButtonDown = true;
var ammo = 100;
var timeHolding = 3;
if (mouseButtonDown == true ammo >= 100 timeHolding == 3);
{
print ("charge attack!")
}
this is all in an update function
im getting this error in the console
“expecting ‘:’ (after the print command) found }”
if i add the : it changes to this
“unexpected token ‘}’ (under the print command)”
“‘;’ expected insert semicolon(after the end } of the function)”
“expecting } found ‘’(in a line that doesn’t exist)”
the tutorial is an older version of unity (ver 3, I’m using 4)
any help would be appreciated
var mouseButtonDown = true;
var ammo = 100;
var timeHolding = 3;
if (mouseButtonDown == true ammo >= 100 timeHolding == 3)
{
print ("charge attack!");
}
@stevej: you are right the semicolon at the end of the if statement was the problem thanks.
what is the advantage of putting the &s out side of the parenthesis?
Maybe it’s just a personal preference, but I find it a lot cleaner. It can sometimes help to avoid some unexpected results in a complex if statement - not in this case though.