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

my code isn't working it says expected can someone help

Discussion in 'Scripting' started by oli_anim8s, Jan 30, 2021.

  1. oli_anim8s

    oli_anim8s

    Joined:
    Jan 30, 2021
    Posts:
    2
    this is my code can someone tell me what's wrong with my code


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

    public class PlayerController : MonoBehaviour
    {

    [SerializeField] Transform playerCamera = null;
    [SerializeField] float mouseSensitivity = 3.5f;
    [SerializeField] float walkSpeed = 6.0f;
    [SerializeField][Range(0.0f, 0.5f)] float moveSmoothTime = 0.3;
    [SerializeField][Range(0.0f, 0.5f)] float mouseSmoothTime = 0.03;

    [SerializeField] bool lockCursor = true;

    float cameraPitch = 0.0f;
    CharacterController controller = null;

    Vector2 currentDir = Vector.zero
    Vector2 currentDirVelocity = Vector2.zero

    Vector2 currentMouseDelta = Vector2.zero
    Vector2 currentMouseDeltaVelocity = Vector2.zero

    void Start()
    {
    controller = GetComponent<CharacterController>();
    if(lockCursor);
    {
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    }
    }

    void Update()
    {
    UpdateMouseLook();
    UpdateMovement();
    }

    void UpdateMouseLook()
    {
    Vector2 targetMouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

    currentMouseDelta = Vector2.SmoothDamp(currentMouseDelta, targetMouseDelta, ref currentMouseDeltaVelocity, mouseSmoothTime);

    cameraPitch -= currentMouseDelta.y * mouseSensitivity;

    cameraPitch = Mathf.Clamp(cameraPitch, -90.0f, 90.0f);

    playerCamera.localEulerAngles = Vector3.right * cameraPitch;

    transform.Rotate(Vector3.up * currentMouseDelta.x * mouseSensitivity);
    }

    void UpdateMovement()
    {
    Vector2 targetDir inputDir = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
    targetDir.Normalize();

    CurrentDir = Vector2.SmoothDamp(currentDir, targetDir, ref currentDirVelocity moveSmoothTime);

    Vector3 velocity = (transform.forward * inputDir.y + transform.right * inputDir.x) * walkSpeed;

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

    oli_anim8s

    Joined:
    Jan 30, 2021
    Posts:
    2
    help me plz ;-;
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    Vryken and Terraya like this.
  4. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    You could at least have looked more closely at what the error told you. It most probably told you that a semicolon ";" was missing, and the line number it occurred for the first time. I can see four instances of this error happening in the upper third of your code.
     
    Vryken likes this.