Unity C# (59,6): error CS1513: } expected

Lazc_coding 41 Reputation points
2022-09-20T02:11:08.05+00:00

My question - Assets\Scripts\NewBehaviourScript.cs(59,6): error CS1513: } expected and what actually does "expected" mean

using System.Collections;  
using System.Collections.Generic;  
using System.Collections.Specialized;  
using System.Threading;  
using UnityEngine;  
using UnityEngine.InputSystem;  
  
//Takes and handles input and movement for a player character  
public class NewBehaviourScript : MonoBehaviour  
{  
  
    public float moveSpeed = 1f;  
    public float collisionOffset = 0.05f;  
    public ContactFilter2D movementFilter;  
    Vector2 movementInput;  
    Rigidbody2D rb;  
    List<RaycastHit2D> castCollision = new List<RaycastHit2D>();  
    // Start is called before the first frame update  
    void Start()  
    {  
        rb = GetComponent<Rigidbody2D>();  
    }  
    private void FixedUpdate()  
    {  
        // If movement input is not 0, try to move  
        if (movementInput != Vector2.zero)  
        {  
            bool success = TryMove(movementInput);  
            if (!success)  
            {  
                success = TryMove(new Vector2(movementInput.x, 0));  
                if (!success)  
                {  
                    success = TryMove(new Vector2(0, movementInput.y));  
                }  
            }  
        }  
    }  
    private bool TryMove(Vector2 direction)  
    {  
        // Check for potential collisions  
        int count = rb.Cast(  
            direction, // X and Y valuses between -1 and 1 that represent the direction from the body to look for collisions  
            movementFilter, // The settings that determine where a collision can occur on such as layer to collide with  
            castCollisions, // List of collisions to store teh found collisions into after the Cast is finished  
            moveSpeed * Time.fixedDeltaTime + collisionOffset); // The amount to cast equal to teh movement plus and offset  
        if (count == 0)  
        {  
            rb.MovePosition(rb.position + direction * moveSpeed * Time.fixedDeltaTime);  
            return true;  
        }  
        else  
        {  
            return false;  
        }  
    }  
    void OnMove(InputValue movementValue) {  
        movementInput = movementValue.Get<Vector2>();  
    } // This is (59,6)  
Developer technologies | C#
{count} votes

Accepted answer
  1. satya karki 996 Reputation points MVP
    2022-09-20T03:27:15.553+00:00

    Hi, seems like you are missing } at the end of the program. Please check it.

    //Takes and handles input and movement for a player character  
    public class NewBehaviourScript : MonoBehaviour  
    {  
      
        public float moveSpeed = 1f;  
        public float collisionOffset = 0.05f;  
        public ContactFilter2D movementFilter;  
        Vector2 movementInput;  
        Rigidbody2D rb;  
        List<RaycastHit2D> castCollision = new List<RaycastHit2D>();  
        // Start is called before the first frame update  
        void Start()  
        {  
            rb = GetComponent<Rigidbody2D>();  
        }  
        private void FixedUpdate()  
        {  
            // If movement input is not 0, try to move  
            if (movementInput != Vector2.zero)  
            {  
                bool success = TryMove(movementInput);  
                if (!success)  
                {  
                    success = TryMove(new Vector2(movementInput.x, 0));  
                    if (!success)  
                    {  
                        success = TryMove(new Vector2(0, movementInput.y));  
                    }  
                }  
            }  
        }  
        private bool TryMove(Vector2 direction)  
        {  
            // Check for potential collisions  
            int count = rb.Cast(  
                direction, // X and Y valuses between -1 and 1 that represent the direction from the body to look for collisions  
                movementFilter, // The settings that determine where a collision can occur on such as layer to collide with  
                castCollisions, // List of collisions to store teh found collisions into after the Cast is finished  
                moveSpeed * Time.fixedDeltaTime + collisionOffset); // The amount to cast equal to teh movement plus and offset  
            if (count == 0)  
            {  
                rb.MovePosition(rb.position + direction * moveSpeed * Time.fixedDeltaTime);  
                return true;  
            }  
            else  
            {  
                return false;  
            }  
        }  
        void OnMove(InputValue movementValue)  
        {  
            movementInput = movementValue.Get<Vector2>();  
        } // This is (59,6)  
    } //add this closing tag  
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.