Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Two Errors

Discussion in 'Scripting' started by BullZeyeBro, Jan 16, 2022.

  1. BullZeyeBro

    BullZeyeBro

    Joined:
    Mar 30, 2021
    Posts:
    3
    Hello i am making a movement for my fps muliplayer game. And i got two errors.
    error CS1513: } expected
    error CS1514: { expected

    this is my code:
    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Photon.Pun;
    5.  
    6. namespace scgFullBodyController
    7.  
    8.     [RequireComponent(typeof(ThirdPersonCharacter))]
    9. public class ThirdPersonUserControl : MonoBehaviour{
    10.         PhotonView view;
    11.  
    12.  
    13.     private void Start()
    14.     {
    15.  
    16.         view = GetComponent<PhotonView>();
    17.     }
    18.    
    19.     void Update()
    20.     {
    21.         if (view.IsMine)  
    22.         {
    23.    
    24.         //IMPORTANT, this script needs to be on the root transform
    25.  
    26.         private ThirdPersonCharacter m_Character; // A reference to the ThirdPersonCharacter on the object
    27.         private Transform m_Cam;                  // A reference to the main camera in the scenes transform
    28.         private Vector3 m_CamForward;             // The current forward direction of the camera
    29.         private Vector3 m_Move;
    30.         private bool m_Jump;                      // the world-relative desired move direction, calculated from the camForward and user input.
    31.         public float sprintSpeed;
    32.         public float walkSpeed;
    33.         public float crouchSpeed;
    34.         [HideInInspector] public bool slide;
    35.         public float slideTime;
    36.         bool crouchToggle = false;
    37.         bool proneToggle = false;
    38.         bool crouch = false;
    39.         bool prone = false;
    40.         bool sprint = false;
    41.         bool canVault = false;
    42.         bool vaulting = false;
    43.         bool strafe;
    44.         bool forwards;
    45.         bool backwards;
    46.         bool right;
    47.         bool left;
    48.         public float vaultCancelTime;
    49.         float horizontalInput;
    50.         float verticalInput;
    51.         public float sensitivity;
    52.         public GameObject cameraController;
    53.         GameObject collidingObj;
    54.         private void Start()
    55.         {
    56.             // get the transform of the main camera
    57.             if (Camera.main != null)
    58.             {
    59.                 m_Cam = Camera.main.transform;
    60.             }
    61.             else
    62.             {
    63.                 Debug.LogWarning(
    64.                     "Warning: no main camera found. Third person character needs a Camera tagged \"MainCamera\", for camera-relative controls.", gameObject);
    65.                 // we use self-relative controls in this case, which probably isn't what the user wants, but hey, we warned them!
    66.             }
    67.  
    68.             // get the third person character ( this should never be null due to require component )
    69.             m_Character = GetComponent<ThirdPersonCharacter>();
    70.         }
    71.  
    72.         void OnCollisionEnter(Collision col)
    73.         {
    74.             if (col.transform.tag == "vaultObject")
    75.             {
    76.                 collidingObj = col.gameObject;
    77.                 canVault = true;
    78.             }
    79.             else
    80.             {
    81.                 canVault = false;
    82.             }
    83.         }
    84.  
    85.         void OnCollisionExit(Collision col)
    86.         {
    87.             canVault = false;
    88.         }
    89.  
    90.         private void Update()
    91.         {
    92.             //Input sensing
    93.  
    94.             verticalInput = Input.GetAxis("Vertical");
    95.             horizontalInput = Input.GetAxis("Horizontal");
    96.  
    97.             if (!m_Jump)
    98.             {
    99.                 m_Jump = Input.GetButtonDown("Jump");
    100.             }
    101.  
    102.             if (m_Jump && canVault)
    103.             {
    104.                 collidingObj.GetComponent<Collider>().enabled = false;
    105.                 m_Jump = false;
    106.                 vaulting = true;
    107.                 Invoke("vaultCancel", vaultCancelTime);
    108.             }
    109.             if (vaulting)
    110.             {
    111.                 m_Jump = false;
    112.             }
    113.             if (Input.GetButtonDown("Crouch"))
    114.             {
    115.                 crouchToggle = !crouchToggle;
    116.                 if (crouchToggle)
    117.                 {
    118.                     crouch = true;
    119.                 }
    120.                 else
    121.                 {
    122.                     crouch = false;
    123.                 }
    124.             }
    125.  
    126.             if (Input.GetButtonDown("Crouch") && prone)
    127.             {
    128.                 proneToggle = !proneToggle;
    129.                 crouch = true;
    130.                 prone = false;
    131.             }
    132.  
    133.             if (Input.GetButtonDown("Prone") && crouch)
    134.             {
    135.                 crouchToggle = !crouchToggle;
    136.                 crouch = false;
    137.                 prone = true;
    138.             }
    139.  
    140.             if (Input.GetButtonDown("Prone"))
    141.             {
    142.                 proneToggle = !proneToggle;
    143.                 if (proneToggle)
    144.                 {
    145.                     prone = true;
    146.                 }
    147.                 else
    148.                 {
    149.                     prone = false;
    150.                 }
    151.             }
    152.  
    153.             if (Input.GetButton("Sprint") && Input.GetButtonDown("Crouch") && m_Character.m_IsGrounded)
    154.             {
    155.                 slide = true;
    156.                 crouch = false;
    157.                 Invoke("slideCancel", slideTime);
    158.             }
    159.  
    160.             if (Input.GetButton("Sprint"))
    161.             {
    162.                 sprint = true;
    163.             }
    164.             else
    165.             {
    166.                 sprint = false;
    167.             }
    168.  
    169.             if (Input.GetButtonDown("Melee"))
    170.             {
    171.                 m_Character.kick();
    172.             }
    173.  
    174.             if (Input.GetAxis("Vertical") < 0)
    175.             {
    176.                 backwards = true;
    177.             }
    178.             else if (Input.GetAxis("Vertical") > 0)
    179.             {
    180.                 forwards = true;
    181.             }
    182.             else if (Input.GetAxis("Vertical") == 0)
    183.             {
    184.                 backwards = false;
    185.                 forwards = false;
    186.             }
    187.  
    188.             if (Input.GetAxis("Horizontal") > 0 || Input.GetAxis("Horizontal") < 0)
    189.             {
    190.                 strafe = true;
    191.             }
    192.             else
    193.             {
    194.                 strafe = false;
    195.             }
    196.  
    197.             m_Character.updateLate(m_Move, crouch, prone, vaulting, forwards, backwards, strafe, horizontalInput, verticalInput);
    198.         }
    199.  
    200.         void vaultCancel()
    201.         {
    202.             vaulting = false;
    203.             canVault = false;
    204.             collidingObj.GetComponent<Collider>().enabled = true;
    205.         }
    206.         // Fixed update is called in sync with physics
    207.         private void FixedUpdate()
    208.         {
    209.             // calculate camera relative direction to move:
    210.             m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized;
    211.             m_Move = verticalInput * m_CamForward * walkSpeed;
    212.  
    213.             if (sprint) m_Move *= sprintSpeed;
    214.  
    215.             // pass all parameters to the character control script
    216.             m_Character.Move(m_Move, crouch, m_Jump, slide, vaulting);
    217.  
    218.             m_Character.HandleGroundMovement(crouch, m_Jump, slide);
    219.             m_Jump = false;
    220.         }
    221.  
    222.         void slideCancel()
    223.         {
    224.             slide = false;
    225.         }
    226.     }
    227.     }
    228.    
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,519
    No, you probably have two typos. Here is how you can fix them.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    Tutorials are a GREAT idea. Tutorials should be used this way:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    Fortunately this is the easiest part to get right: Be a robot. Don't make any mistakes.
    BE PERFECT IN EVERYTHING YOU DO HERE!!

    If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!
     
    BullZeyeBro likes this.
  3. BullZeyeBro

    BullZeyeBro

    Joined:
    Mar 30, 2021
    Posts:
    3