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

Bug help me fix 3x syntax error ',' expected 2x { expected type or namescape def or end-of-file 2x

Discussion in 'Scripting' started by vega20029027, Aug 5, 2023.

Thread Status:
Not open for further replies.
  1. vega20029027

    vega20029027

    Joined:
    Aug 4, 2023
    Posts:
    11
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Movment : MonoBehaviour
    6.    [SerializeField] Transform playerCamara;
    7.    [SerializeField][Range(0,0f, 0.5f)] float mouseSmoothTime = 0.03f;
    8.    [SerializeField] bool cursorLock = true;
    9.    [SerializeField] float mouseSensitivity = 3.5f;
    10.    [SerializeField] float Speed = 6.0f;
    11.    [SerializeField][Range(0,0f, 0.5f)] float mouseSmoothTime = 0.03f;
    12.    [SerializeField] float gravity = 30f;
    13.    [SerializeField] Transform grouncheck;
    14.    [SerializeField] LayersMask ground;
    15.  
    16.    public float jumpHeight = 6f;
    17.    float velocityY;
    18.    bool isGrounded;
    19.  
    20.    float camaraCap;
    21.    Vector2 currentMouseDelta;
    22.    Vector2 currentMouseDeltaVelocity;
    23.  
    24.    CharacterController controller;
    25.    Vector2 currnetDir;
    26.    Vector2 currentDirVelocity;
    27.    Vector2 velocity;
    28.  
    29. {
    30.  
    31.     void Start()
    32.     {
    33.         controller = GetComponent<CharacterController>();
    34.  
    35.         if (cursorLock)
    36.         {
    37.             Curoser.lockState = CursorLockMode.Locked;
    38.             cursorLock.Visable = true;
    39.         }
    40.      
    41.     }
    42.  
    43.     // Update is called once per frame
    44.     void Update()
    45.     {
    46.       UpdateMouse();
    47.       UpdateMove();
    48.     }
    49. }
    50.    
    51.  
    52.       void UpdateMouse()
    53.       {
    54.         Vector2 targetMouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
    55.      
    56.         currentMouseDelta = Vector2.SmoothDamp(currentMouseDelta, targetMouseDelta, ref currentMouseDeltaVelocity, mouseSmoothTime);
    57.  
    58.         camaraCap = currentMouseDelta.y * mouseSensitivity;
    59.  
    60.         camaraCap = Mathf.Clamp(camaraCap, -90,0f, 90,0f);
    61.  
    62.         playerCamara.localEulerAngles = Vector3.right * camaraCap;
    63.  
    64.         transform.Roatate(Vector3.up * currentMouseDelta.x * mouseSensitivity);
    65.  
    66.       }
    67.  
    68.       void UpdateMove()
    69.       {
    70.      
    71.         isGrounded = Physics.CheckSphere(groundCheck.position, 0.2f, ground);
    72.  
    73.         Vector2 targetDir = new Vector2(Input.GetAxisRaw("Horizantal"), Input.GetAxisRaw("Vertical"));
    74.         targetDir.Dir.Noramlize();
    75.  
    76.         currnetDir = Vector2.SmoothDamp(currnetDir, targetDir, ref currentDirVelocity, mouseSmoothTime);
    77.  
    78.         velocityY += gravity * 2f * Time.DeltaTime;
    79.  
    80.         Vector3 velocity = (transform.forward * currnetDir.y * trasnform.right * currnetDir.x * Speed + Vector3.up * velocityY);
    81.  
    82.         controller.Move(velocity * Time.DeltaTime);
    83.  
    84.         if (isGrounded && Input.GetButtonDown("Jump"))
    85.         {
    86.             velocityY = Mathf.Sort(jumpHeight * -2f = gravity);
    87.         }
    88.  
    89.        
    90.  
    91.          if (isGrounded! && controller.velocity.y < -1f)
    92.          {
    93.              velocity = -8f;
    94.          }
    95.       }
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Movment : MonoBehaviour
    [SerializeField] Transform playerCamara;
    [SerializeField][Range(0,0f, 0.5f)] float mouseSmoothTime = 0.03f;
    [SerializeField] bool cursorLock = true;
    [SerializeField] float mouseSensitivity = 3.5f;
    [SerializeField] float Speed = 6.0f;
    [SerializeField][Range(0,0f, 0.5f)] float mouseSmoothTime = 0.03f;
    [SerializeField] float gravity = 30f;
    [SerializeField] Transform grouncheck;
    [SerializeField] LayersMask ground;

    public float jumpHeight = 6f;
    float velocityY;
    bool isGrounded;

    float camaraCap;
    Vector2 currentMouseDelta;
    Vector2 currentMouseDeltaVelocity;

    CharacterController controller;
    Vector2 currnetDir;
    Vector2 currentDirVelocity;
    Vector2 velocity;

    {

    void Start()
    {
    controller = GetComponent<CharacterController>();

    if (cursorLock)
    {
    Curoser.lockState = CursorLockMode.Locked;
    cursorLock.Visable = true;
    }

    }

    // Update is called once per frame
    void Update()
    {
    UpdateMouse();
    UpdateMove();
    }
    }


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

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

    camaraCap = currentMouseDelta.y * mouseSensitivity;

    camaraCap = Mathf.Clamp(camaraCap, -90,0f, 90,0f);

    playerCamara.localEulerAngles = Vector3.right * camaraCap;

    transform.Roatate(Vector3.up * currentMouseDelta.x * mouseSensitivity);

    }

    void UpdateMove()
    {

    isGrounded = Physics.CheckSphere(groundCheck.position, 0.2f, ground);

    Vector2 targetDir = new Vector2(Input.GetAxisRaw("Horizantal"), Input.GetAxisRaw("Vertical"));
    targetDir.Dir.Noramlize();

    currnetDir = Vector2.SmoothDamp(currnetDir, targetDir, ref currentDirVelocity, mouseSmoothTime);

    velocityY += gravity * 2f * Time.DeltaTime;

    Vector3 velocity = (transform.forward * currnetDir.y * trasnform.right * currnetDir.x * Speed + Vector3.up * velocityY);

    controller.Move(velocity * Time.DeltaTime);

    if (isGrounded && Input.GetButtonDown("Jump"))
    {
    velocityY = Mathf.Sort(jumpHeight * -2f = gravity);
    }



    if (isGrounded! && controller.velocity.y < -1f)
    {
    velocity = -8f;
    }
    }[/code]
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    Looks like you tried to use code tags, but maybe deleted the starting tag.

    Luckily, your typo at the top at least is easy to spot.

    upload_2023-8-5_17-14-33.png
    That bracket is not where it's suppose to be.
     
    vega20029027 likes this.
  3. vega20029027

    vega20029027

    Joined:
    Aug 4, 2023
    Posts:
    11
    where do i put it
     
  4. wideeyenow_unity

    wideeyenow_unity

    Joined:
    Oct 7, 2020
    Posts:
    728
    Hopefully you're able to figure out how to get rid of the duplicated text.

    But I can already see you have multiple misspellings, and have your brackets in all the wrong places.
     
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    You should be able to look at any other script to see where it goes. But, a hint is declaring variables should always be within the { and not before it.
     
  6. wideeyenow_unity

    wideeyenow_unity

    Joined:
    Oct 7, 2020
    Posts:
    728
    @Brathnann are you able to see this site in dark mode??? please teach me! A white background is like a High-powered LED flashlight in my face, lol
     
  7. vega20029027

    vega20029027

    Joined:
    Aug 4, 2023
    Posts:
    11
    where do i put the bracket
     
  8. vega20029027

    vega20029027

    Joined:
    Aug 4, 2023
    Posts:
    11
    im new to unity so i followed a tutorial so idk how to fix it please help @Brathnann
     
  9. wideeyenow_unity

    wideeyenow_unity

    Joined:
    Oct 7, 2020
    Posts:
    728
    But yes, the open bracket at 29 needs to be at 6. The close bracket at 49 needs to be at 96. And the misspellings I'll figure out later, lol
     
  10. wideeyenow_unity

    wideeyenow_unity

    Joined:
    Oct 7, 2020
    Posts:
    728
    Standard practice of class containment should look like this:
    Code (CSharp):
    1. public class MyClass : MonoBehaviour
    2. {
    3.    // variable declarations
    4.    // Start() { }
    5.    // Update() { }
    6.    // functions/methods { }
    7. }
    It doesn't have to be in that particular order, but the first and the end bracket do.
     
    Last edited: Aug 5, 2023
  11. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
  12. vega20029027

    vega20029027

    Joined:
    Aug 4, 2023
    Posts:
    11
    it left me with 4 errors 'RangeAttribute' dose not contain a constructor that takes 3 arguments x2
    the type 'Movment' already contains a defition for 'mouseSmoothTime'
    the type or namescape Name LayersMask could not be found
     
  13. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    It's a Firefox plugin called Dark Reader. It might be available on other browsers as well. :)
     
  14. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    If you are following a tutorial, then you should go back to the tutorial. While there are some bad tutorials, chances are this isn't one of them and I suggest looking over their script line by line and comparing it to yours. That will be super helpful. To Quote "Everything must be typed exactly right!".
     
  15. vega20029027

    vega20029027

    Joined:
    Aug 4, 2023
    Posts:
    11
    i did it is if you can help me with fixing the code that would be great cus i reallly want my player to move its very disapoiting when your cide diosent work
     
  16. wideeyenow_unity

    wideeyenow_unity

    Joined:
    Oct 7, 2020
    Posts:
    728
    That's because your spelling is horrible.. no offense.. But everything in code is "exact", and any misplaced letter or symbol, especially "CAPITAL" versus "lowercase" letters can easily break your code.

    So you may be in a hurry, which I admit I do myself, but you really gotta take your time and read and reread and reread again to make sure everything is typed exactly right.. Or nothing will work... ever...
     
  17. wideeyenow_unity

    wideeyenow_unity

    Joined:
    Oct 7, 2020
    Posts:
    728
    Now, I went through and fixed all your spelling errors, but it would just be easier to delete that script and make a new one, with this pasted into it:

    Code (CSharp):
    1. public class Movement : MonoBehaviour // was Movment
    2. {
    3.     [SerializeField] Transform playerCamera; // was playerCamara
    4.     [SerializeField][Range(0,0f, 0.5f)] float mouseSmoothTime = 0.03f;
    5.     [SerializeField] bool cursorLock = true;
    6.     [SerializeField] float mouseSensitivity = 3.5f;
    7.     [SerializeField] float Speed = 6.0f;
    8.     [SerializeField][Range(0,0f, 0.5f)] float mouseSmoothTime = 0.03f;
    9.     [SerializeField] float gravity = 30f;
    10.     [SerializeField] Transform groundCheck; // was grouncheck
    11.     [SerializeField] LayersMask ground;
    12.  
    13.     public float jumpHeight = 6f;
    14.     float velocityY;
    15.     bool isGrounded;
    16.  
    17.     float cameraCap; // was camaraCap
    18.     Vector2 currentMouseDelta;
    19.     Vector2 currentMouseDeltaVelocity;
    20.  
    21.     CharacterController controller;
    22.     Vector2 currentDir; // was currnetDir
    23.     Vector2 currentDirVelocity;
    24.     Vector2 velocity;
    25.     void Start()
    26.     {
    27.         controller = GetComponent<CharacterController>();
    28.         if (cursorLock)
    29.         {
    30.             Cursor.lockState = // was Curoser.lockState
    31.                    CursorLockMode.Locked;
    32.             cursorLock.Visable = true;
    33.         }
    34.     }
    35.  
    36.     void Update()
    37.     {
    38.         UpdateMouse();
    39.         UpdateMove();
    40.     }
    41.  
    42.     void UpdateMouse()
    43.     {
    44.         Vector2 targetMouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
    45.  
    46.         currentMouseDelta = Vector2.SmoothDamp(currentMouseDelta, targetMouseDelta, ref currentMouseDeltaVelocity, mouseSmoothTime);
    47.  
    48.         cameraCap = currentMouseDelta.y * mouseSensitivity;
    49.  
    50.         cameraCap = Mathf.Clamp(cameraCap, -90,0f, 90,0f);
    51.  
    52.         playerCamera.localEulerAngles = Vector3.right * cameraCap;
    53.  
    54.         transform.Rotate( // was transform.Roatate
    55.             Vector3.up * currentMouseDelta.x * mouseSensitivity);
    56.     }
    57.     void UpdateMove()
    58.     {
    59.         isGrounded = Physics.CheckSphere(groundCheck.position, 0.2f, ground);
    60.  
    61.         Vector2 targetDir = new Vector2(
    62.             Input.GetAxisRaw("Horizontal"), // was Horizantal
    63.             Input.GetAxisRaw("Vertical"));
    64.         targetDir.Dir.Normalize(); // was Dir.Noramlize
    65.  
    66.         currentDir = // was currnetDir
    67.             Vector2.SmoothDamp(currentDir, targetDir, ref currentDirVelocity, mouseSmoothTime);
    68.  
    69.         velocityY += gravity * 2f * Time.DeltaTime;
    70.  
    71.         Vector3 velocity = (transform.forward * currentDir.y * transform.right // was trasnform
    72.                      * currentDir.x * Speed + Vector3.up * velocityY);
    73.  
    74.         controller.Move(velocity * Time.DeltaTime);
    75.  
    76.         if (isGrounded && Input.GetButtonDown("Jump"))
    77.         {
    78.             velocityY = Mathf.Sort(jumpHeight * -2f = gravity);
    79.         }
    80.  
    81.         if (isGrounded! && controller.velocity.y < -1f)
    82.         {
    83.             velocity = -8f;
    84.         }
    85.     }
    86. }
    Because changing the script name after it's been made is a nightmare to fix. So much easier to just make a new one. So test out the code I provided and see what fails then. But be sure to give us a proper line(number) error so we can see where the issue is.

    Edit: I must have reread this script 10 times, and I'm still finding spelling mistakes.. oof.. never doing that again, lol
     
    Last edited: Aug 6, 2023
    Kurt-Dekker likes this.
  18. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Closing this thread because the forum is not here to correct typos or teach the very basics of C#. The forums assume a basic knowledge of the language.
     
    Kurt-Dekker likes this.
Thread Status:
Not open for further replies.