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

Question Got an error while trying to make player movement in a 2D template

Discussion in 'Scripting' started by Nycticc, Oct 6, 2023.

  1. Nycticc

    Nycticc

    Joined:
    Oct 6, 2023
    Posts:
    3
    I got an error called "Assets\PlayerMovement.cs(9,37): CS1002: ;expected

    can anyone help please?
    here is my code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerMovement : MonoBehaviour
    6. {
    7.     private float horizontal;
    8.     private float speed = 8f;
    9.     private float jumpingPower = 16f
    10.     private bool isFacingRight = true;
    11.  
    12.     [SerializeField] private Rigidbody2D rb;
    13.     [SerializeField] private Transform groundCheck;
    14.     [SerializeField] private LayerMask groundLayer;
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         horizontal = Input.GetAxisRaw("Horizontal");
    20.  
    21.         if (Input.GetButtonDown("Jump") && IsGrounded())
    22.         {
    23.             rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
    24.         }
    25.  
    26.         if (Input.GetButtonUp("Jump") && rb.velocity.y * 0.5f);
    27.         {
    28.             rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
    29.         }
    30.  
    31.         Flip();
    32.     }
    33.  
    34.  
    35.     private void FixedUpdate()
    36.     {
    37.         rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
    38.     }
    39.  
    40.     private bool IsGrounded()
    41.     {
    42.         return Physhics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
    43.     }
    44.  
    45.     private void Flip()
    46.     {
    47.         if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
    48.         {
    49.             isFacingRight = !isFacingRight;
    50.             Vector3 localScale = transform.localScale;
    51.             localScale.x *= -1f;
    52.             transform.localScale = localScale;
    53.         }
    54.     }
    55. }
    56.  
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    Look at the error, it tells you exactly what is wrong!

    PlayerMovement.cs
    Line 9
    Column 37
    Missing ;

    Look, find, fix, profit. :)
     
  3. Nycticc

    Nycticc

    Joined:
    Oct 6, 2023
    Posts:
    3






    Thanks so much! I didnt know what the numbers meant:)
     
    MelvMay likes this.