Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

2D Character Controller Parser Error?

Discussion in 'Animation' started by CodBadondayyyy, Jun 7, 2017.

  1. CodBadondayyyy

    CodBadondayyyy

    Joined:
    Jun 5, 2017
    Posts:
    1
    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
     
  2. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    196
    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: https://forum.unity3d.com/threads/using-code-tags-properly.143875/

    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:

    Code (CSharp):
    1. if (Input.GetAxisRaw ("Horizontal") < 0.5f || Input.GetAxisRaw ("Horizontal") > -0.5f)
    2. {
    3.     myRigidbody.velocity = new Vector2 (0f, myRigidbody.velocity.y);
    4. }
    5.  
    6. if (Input.GetAxisRaw("Vertical") < 0.5f || Input.GetAxisRaw("Vertical") > -0.5f )
    7. {
    8.     myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, 0f);
    9. }
    That should fix the parsing error.

    Cheers,
    TrickyHandz