Need help, errors I don't understand.

(Before I start I have no knowledge in scripting or coding and have only used Unity 5.2 for about 30 minutes.)

I recently added something into the script of my game to allow my ball to jump. I went back into unity to test it and 4 error messages showed up in the console.

Assets/BallControl.js(17,22): BCE0044: expecting ), found ‘=’.
Assets/BallControl.js(17,23): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/BallControl.js(17,34): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/BallControl.js(17,34): BCE0043: Unexpected token: ;.

I have tried many things to try to fix it. This is my script for the controls of my ball:

#pragma strict

var rotationSpeed = 100;

var jumpHeight = 8;

private var isFalling = false;

function Update () {

//Handle ball rotation.

var rotation : float = Input.GetAxis (“Horizontal”) * rotationSpeed;

rotation *= Time.deltaTime;

GetComponent.().AddRelativeTorque (Vector3.back * rotation);

if (Input.GetKeyDown (KeyCode.W))

(

rigidbody.velocity.y = jumpHeight;

)

}

If anyone could help me with this it would be appreciated.
Thank you.

You have parentheses after your if statement here

if (Input.GetKeyDown (KeyCode.W))
(
    rigidbody.velocity.y = jumpHeight;
)

change it to curley braces like this

if (Input.GetKeyDown (KeyCode.W))
{
    rigidbody.velocity.y = jumpHeight;
}

Ahhh thanks, the video I was watching they looked a lot like parentheses. Thanks so much I can finally continue my work!

Wait, I am using JavaScript for my game as it was recommended for new devs, is it the same with CSharp?

Yes, I believe using {} for if statements is the same for C# and javascript.
I also recommend starting with C# instead of javascript. It seems unity is moving towards C# more with all their tutorials and what not, so it may be easier as a beginner to start with that.
This is just an opinion from an inexperienced coder though =)

Ok thanks for your input, I have textures now on my ball and ground :smile: (The jumping is working fine).

1 Like

I’ll second that opinion. UnityScript has a lot of gotchas waiting to catch the unwary. Learn it if you want. But anticipate being told to switch to C# on every other forum post. :roll_eyes:

1 Like

Ok