Search Unity

error CS1519: invalid token "if" in class, record, or interface member declaration

Discussion in 'Getting Started' started by DZetDevX, Mar 23, 2023.

  1. DZetDevX

    DZetDevX

    Joined:
    Mar 23, 2023
    Posts:
    1
    Hello im new to game development. I tried a third person camera on youtube, he use cinemachine for it. Then, i follow his code as same as possible. But when i open the console, it appear lot of promp error like these

    and this is my code


    please anyone help me
     

    Attached Files:

  2. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    497
    Don't just jump to a random error message in the list (which you appear to have done). Look at the first one, and then fix that as it most likely has a cascade of errors happening because of that.

    Please do not post screenshots of code as that makes it impossible for us to copy and paste code responses as now we have to type out any code fixes (and if it is a lot of fixes it gets long-winded for us to do it).

    Anyway, looking at the first error in the list it is on line 22. You appear to have made 2 mistakes on the line before (line 21), so have therefore not followed the tutorial properly:

    1 - you have put
    private void update()
    , when it should be
    private void Update()
    . Capitalisation matters, and so does spelling - if you do not type the method name correctly (especially for any Unity in-built methods) they are just not going to run. This will not actually fix any error messages, but will actually make sure that Unity will run that method.
    2 - on that same line you have put
    ;
    at the end of the line. That is effectively telling the method that is the end of it, so anything you type afterwards (which should be the bulk of the method) is not inside a method and is therefore not valid. Remove the
    ;
    from that line.

    If you fix the above you will probably find that most/all of the rest of the errors disappear.