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

Discussion Assets\Scripts\Player\PlayerController.cs(34,23): error CS1002: ; expected. Help Please.

Discussion in 'Documentation' started by SpaceNerdM64, Aug 9, 2022.

  1. SpaceNerdM64

    SpaceNerdM64

    Joined:
    Aug 7, 2022
    Posts:
    1
    So I know what the error means. However, I am not sure where the error is taking place considering I have gone over my script many times looking for where I am missing the semicolon. I may just be blind, so if that is the case I am sorry.

    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.  
    9.     private bool isMoving;
    10.     private Vector2 input;
    11.  
    12.     private void Update()
    13.     {
    14.         if (!isMoving)
    15.         {
    16.             input.x = Input.GetAxisRaw("Horizontal");
    17.             input.y = Input.GetAxisRaw("Vertical");
    18.             if(input != Vector2.zero)
    19.             {
    20.                 var targetPos = transform.position;
    21.                 targetPos.x += input.x;
    22.                 targetPos.y += input.y;
    23.  
    24.                 StartCoroutine(Move(targetPos));
    25.             }
    26.         }
    27.         IEnumerator Move(Vector3 targetPos)
    28.         {
    29.             isMoving = true;
    30.  
    31.             while ((targetPos - transformation.position).sqrMagnitude > Mathf.Epsilon)
    32.             {
    33.                 transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
    34.                 yeild return null;
    35.             }
    36.             transform.position = targetPos;
    37.  
    38.             isMoving = false;
    39.         }
    40.     }
    41. }
    42.