2D Character Controller Parser Error?

Hi,

I’m new to unity and coding in general, but have been working through some tutorials and guides on creating a top down 2D RPG style game. I’m hoping this will broaden my knowledge and give me some satisfaction when (and if) I complete it.

I feel like I’ve done well up till now, but seem to be getting a parser error flag up against some of the code I’ve recently added (to stop my player bouncing when walking against objects). Hopefully someone can help. Code below:

if (Input.GetAxisRaw (“Horizontal”) < 0.5f || Input.GetAxisRaw (“Horizontal”) > -0.5f)
{
myRigidbody.velocity = new Vector2 (0f, myRigidbody.velocity.y)
}

if (Input.GetAxisRaw(“Vertical”) < 0.5f || Input.GetAxisRaw(“Vertical”) > -0.5f )
{
myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, 0f)
}

Thanks,
Conor

Welcome to the community @CodBadondayyyy
First things first, it is very helpful if you put any posting of code within Code tags so that it formats nicely. See here for details: Using code tags properly - Unity Engine - Unity Discussions

To answer your question, it looks like you are just missing the required semicolons at the end of the lines that are assigning velocity. It should look like this:

if (Input.GetAxisRaw ("Horizontal") < 0.5f || Input.GetAxisRaw ("Horizontal") > -0.5f)
{
    myRigidbody.velocity = new Vector2 (0f, myRigidbody.velocity.y);
}

if (Input.GetAxisRaw("Vertical") < 0.5f || Input.GetAxisRaw("Vertical") > -0.5f )
{
    myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, 0f);
}

That should fix the parsing error.

Cheers,
TrickyHandz