locked
ERROR CS1513 expected (C#) RRS feed

  • Question

  • Script below:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class Player : MonoBehaviour
    {
        private Rigidbody2D myRigidbody;
     // Use this for initialization
     void Start ()
        {
            myRigidbody = GetComponent<Rigidbody2D>();
     }
     
     // Update is called once per frame
     void Update ()
        {
            float horizontal = Input.GetAxis("Horizontal");
            HandleMovement(horizontal);
        }
        private void HandleMovement(float horizontal)
        {
            myRigidbody.velocity = new Vector2(horizontal, myRigidbody.velocity.y);
        }

    Tuesday, May 29, 2018 3:08 PM

All replies

  • The 'CS' errors are pretty easy to look up and it should be clear from the documentation:

    CS1513

    In this case, a missing closing curly bracket (at the end of your script to close the class).

    • Proposed as answer by Tim Roberts Wednesday, May 30, 2018 7:20 AM
    Tuesday, May 29, 2018 3:14 PM
  • Hi MisledPillow4,

    Please try the code below.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Player : MonoBehaviour
     {
         private Rigidbody2D myRigidbody;
      // Use this for initialization
      void Start ()
         {
             myRigidbody = GetComponent<Rigidbody2D>();
         }
      
      // Update is called once per frame
      void Update ()
         {
             float horizontal = Input.GetAxis("Horizontal");
    
            HandleMovement(horizontal);
         }
    
        private void HandleMovement(float horizontal)
         {
             myRigidbody.velocity = new Vector2(horizontal, myRigidbody.velocity.y);
         }
     }

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 1, 2018 7:03 AM