- Home /
Formatting problems in Script
I have part of a script that has a syntax problem:
function Update () {
if (!inFreefall && Input.GetButton("Fire1")) {
if (transform.forward = Vector3.forward){
Physics.gravity = Vector3(0, 0, 9.81);
}
}
The lines with the second "if" and "Physics" are lines 15 and 16 respectively. Here are the errors:
15: expecting ), found =
15: Unexpected token: )
16: expecting :, found =
What's with this thing?
Answer by SrBilyon · May 30, 2011 at 10:25 PM
To follow up with SirGive, here is a cleaner/expanded version:
function Update ()
{
if (!inFreefall && Input.GetButton("Fire1"))
{
if (transform.forward = Vector3.forward)
{
Physics.gravity = Vector3(0, 0, 9.81);
}
}
}
$$anonymous$$e was explaining the answer without giving it.
Answer by GlennHeckman · May 30, 2011 at 11:34 PM
1) You were missing a closing bracket "}" for your if statement.
2) When checking for equality, you need 2 "=" signs.
if(1 == 1)
{
// do something
}
When assigning a value, you use 1 "=" sign.
a = b;
I fixed your problem below ... Good Luck!
function Update ()
{
if (!inFreefall && Input.GetButton("Fire1"))
{
if (transform.forward == Vector3.forward)
{
Physics.gravity = Vector3(0, 0, 9.81);
}
}
}
bah, I didn't even notice that :P But from his code, it looks like he is missing a bracket.
Thanks, I didn't realize that; I'll check it out and let you know.
Your answer
Follow this Question
Related Questions
3 java errors on a basic shooting script? 2 Answers
SwipeControl package error in unity iPhone 1.7 1 Answer
scripting problem with if statements 1 Answer
error message for var 1 Answer
Problem with "Pick up key" script 2 Answers