Script is Acting Wierd

@username hi guys, my script is acting kinda wierd. It gives be an error saying unexpected symbol ‘public’ but I don’t know what’s wrong. Here is the line of code.

                `public void Jump()
	{
		myrigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, jumpHeight);
	}`

1 Answer

1

There is no problem with that lines. The problem is you have it in another method. Make sure you close the other method with " } " before new method.
eg.:

Wrong :

public void Start(){

	public void Jump()
	{
		GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, 10);
	}
	}//End of Start

Good :

public void Start(){

	}//End of Start
	public void Jump()
	{
		GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, 10);
	}

It works but then I go to unity and it says parsing error

Probably you're missing another " } " at the end. Without seeing the script it is hard to tell. We're not magicians here :D