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?
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);
}
}
}
-
You were missing a closing bracket “}” for your if statement.
-
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);
}
}
}