Search Unity

Question Tile Based Movement Building Collider problems

Discussion in '2D' started by Squishypie33, Jun 24, 2021.

  1. Squishypie33

    Squishypie33

    Joined:
    Jun 24, 2021
    Posts:
    1
    I am new to unity and am attempting a tile based movement RPG game. I am getting 2 errors. CS1513 and error CS1002. CS1002 expects a ; to be placed on lines 63 and 70, but that doesn't make too much sense to me. error CS1513 expects a } on those same lines (63 and 70). However, as you will probably see, there is already a } on line 70 and on line 63, I have no idea where I would even put it. I have read a couple other forums like this, but am still confused. Line 70 is the last line and line 63 is the Physics2D.OverlapCircle. Here is my code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.     public float moveSpeed;
    8.     public LayerMask solidObjectsLayer;
    9.    
    10.     private bool isMoving;
    11.     private Vector2 input;
    12.  
    13.     private Animator animator;
    14.    
    15.     private void Awake()
    16.     {
    17.         animator = GetComponent<Animator>();
    18.     }
    19.  
    20.     private void Update()
    21.     {
    22.         if (!isMoving)
    23.         {
    24.             input.x = Input.GetAxisRaw("Horizontal");
    25.             input.y = Input.GetAxisRaw("Vertical");
    26.  
    27.             // remove diagnol movement
    28.             if (input.x != 0) input.y = 0;
    29.  
    30.             if (input != Vector2.zero)
    31.             {
    32.                 animator.SetFloat("moveX", input.x);
    33.                 animator.SetFloat("moveY", input.y);
    34.  
    35.                 var targetPos = transform.position;
    36.                 targetPos.x += input.x;
    37.                 targetPos.y += input.y;
    38.  
    39.                 if (IsWalkable(targetPos))
    40.                 StartCoroutine(Move(targetPos));
    41.             }
    42.         }
    43.  
    44.         animator.SetBool("isMoving", isMoving);
    45.     }
    46.  
    47.     IEnumerator Move(Vector3 targetPos)
    48.     {
    49.         isMoving = true;
    50.  
    51.         while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
    52.         {
    53.             transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
    54.             yield return null;
    55.         }
    56.         transform.position = targetPos;
    57.  
    58.         isMoving = false;
    59.     }
    60.  
    61.     private bool IsWalkable(Vector3 targetPos)
    62.     {
    63.         Physics2D.OverlapCircle(targetPos, 0.3f, solidObjectsLayer) != null)
    64.         {
    65.             return false;
    66.         }
    67.  
    68.         return true;
    69.     }
    70. }
    71.  

    Thanks for any help and sorry in advance for any bad etiquette, this is my first post!
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    This isn't new to Unity but more new to C# because these are basic C# errors and nothing to do with Unity.

    This line doesn't make sense and isn't correct C#. It seems like it's supposed to be a "If () { do something }" statement but only you know that. You're already using an "if" statement above so it seems you might have just copied this code?

    I would suggest looking up what the if statement does such as here.

    This is the scripting forum. The title of the thread would seem to indicate that it's a problem with that when it's a C# syntax issue.