Search Unity

error Assets/PlayerMovement.cs(14,22): error CS1002: ; expected

Discussion in 'Scripting' started by pototo1567, Apr 5, 2021.

  1. pototo1567

    pototo1567

    Joined:
    Apr 5, 2021
    Posts:
    5
    im new to unity and i have these errors Assets/PlayerMovement.cs(14,22): error CS1002: ; expected
    and
    Assets/PlayerMovement.cs(14,32): error CS1519: Invalid token ';' in class, struct, or interface member declaration
    here's my code

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour
    {
    public CharacterController controller;

    public float speed = 12f;
    public float gravity = -9.81f;

    public Transform groundCheck;
    public float groundDistance = 0.4f;
    Public LayerMask groundMask;

    Vector3 velocity;
    bool isGrounded;

    // Update is called once per frame
    void Update()
    {
    isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

    if(isGrounded && velocity.y < 0)
    {
    velocity.y = -2f;
    }

    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");

    Vector3 move = transform.right * x + transform.forward * z;

    controller.Move(move * speed * Time.deltaTime);

    velocity.y += gravity * Time.deltaTime;

    controller.Move(velocity * Time.deltaTime);
    }
    }

    can anyone help me?
     
    jasonasaad2 likes this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
  3. pototo1567

    pototo1567

    Joined:
    Apr 5, 2021
    Posts:
    5
    sorry i meant help me fix my code
     
  4. fmoodey

    fmoodey

    Joined:
    Jan 30, 2021
    Posts:
    3
    You need to change the capital "P" in public on line 14.

    From this :
    Code (CSharp):
    1. Public LayerMask groundMask;
    To this:
    Code (CSharp):
    1. public LayerMask groundMask;
     
    pototo1567 and jasonasaad2 like this.
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    I can't read your code. That's why I suggested adding code tags as is required in the forum.
     
  6. pototo1567

    pototo1567

    Joined:
    Apr 5, 2021
    Posts:
    5
    ok thank you =3
     
  7. vilten10

    vilten10

    Joined:
    Aug 5, 2021
    Posts:
    1
    Code (CSharp):
    1. using UnityEngine.ui;
    2.  
    3. public class movement2d : MonoBehaviour
    4. {
    5.     public float MovementSpeed =1.5;
    6.     private  void Start()
    7.     {
    8.    
    9.     }
    10.  
    11.   private  void Update()
    12.     {
    13.        var movement = Input().GetAxis("Horizontal");
    14.        transform.position += NEW Vector3(movement, 0,0 )* Time.deltaTime  *  MovementSpeed;
    15.     }
    16. }
    17.  
    I HAVE CS1002 ERROR I CANT FIX IT PLS HELP ME
     
  8. Wieditleestisgek

    Wieditleestisgek

    Joined:
    Dec 18, 2016
    Posts:
    43
    new is in all caps. it needs to be all lower case.

    is your autocomplete working?
    it should help prevent simple things like this.