Help! I am trying to make a simple infinite runner movement code, but for some reason, it's not working.

using UnityEngine;
using System.Collections;

public class PlayerControl : MonoBehaviour {

public float moveSpeed;
public float jumpForce;

private Rigidbody2D myRigidbody;

void Start () {
	myRigidbody = GetComponent<Rigidbody2D> ();
}

// Update is called once per frame

void Update () {
myRigidbody.velocity = new Vector2 (moveSpeed, myRigidbody.velocity.y);

	if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0)
    (
			myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, jumpForce)
		)
	)	
	}

}

The last “}” is there because I need to close the code, but it just says “unexpected symbol ‘}’.” When I delete }, it says “unexpected symbol ‘end file’”

Hello!

It appears that your ‘if’ statement is using the wrong kind of brackets.

‘If’ statements are written like this:

if () //Put your arguments/comparisons inside of these curly brackets.
{
     //Put your code here.
}

Inside of the parentheses, you put your arguments/comparisons.
And inside of the curly brackets, you put your code.

So, you should replace this:

if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0)
     (
             myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, jumpForce)
         )
     )  

With this:

if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0))
{
             myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, jumpForce);
}

Also, don’t forget about semicolons at the end of each line of code!

I hope I was able to help you!

@TheShrunk

Thanks a ton, TheShrunk! For some reason, though, Im getting errors still. At the ; at the end of my code, it says “Unexpected symbol end” of file error. Whatever this means, “the namespace global already contains a definiton for PlayerController.” Finally, it says “Unexpected Symbol }.” I know that I need the } to end the code, so I don’t know what to do. Finally, I have a warning (Possible mistaken empty statement)

If it’s not much trouble, could you help?

using UnityEngine; using System.Collections;
public class PlayerControl : MonoBehaviour {
public float moveSpeed;
public float jumpForce;
private Rigidbody2D myRigidbody;

void Start () {
	myRigidbody = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () { myRigidbody.velocity = new Vector2 (moveSpeed,myRigidbody.velocity.y);
	if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown 
	(0))
	{
		myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, jumpForce); 
	}

Thanks for reading, adios, and have a good day/night/evening/twilight/morning/afternoon/christmas/hannuka/birthday/mothers-daughters-urns-gardeners-brothers quinceanara, depending on your timezone and religion.