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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

how to fix player camera

Discussion in 'Scripting' started by rileydj2009, Apr 22, 2021.

  1. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    ok so im trying to make a player movement in unity but when im supposed to move the camera in to the player camera section play camera doesent pop up does anybody know how to make it appear?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Your question doesn't make any sense. Can you restate it more clearly?

    What do you mean by "when I'm supposed to"? What pop up are you talking about? What do you mean by "move the camera in to the player camera section"?
     
  3. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    sorry im not good with explaining things i was watching a tutorial on how to make movements ill send you an image of what there screen looked like and mine
     
  4. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    this is my screen
     

    Attached Files:

  5. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    and thats theres
     

    Attached Files:

  6. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    im supposed to drag the camera in the player camera on charecter controller in a section called player camera but its not there for me
     
  7. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    go into your player controller script, I assume your tutorial told you to define a variable there like:

    public Transform playerCamera;

    right?
    make sure you have this defined, make sure it is either public or has the [SerializeField] in front of it

    not all field are exposed to the inspector:
    public fields are automaticly exposed
    private or protected ones need to be serializeable for exposure thus [SerializeField]

    Edit:
    just as a general explaination for your problem:
    the player camera does not pop up because you did not define in your code that your player controller has an exposed field called player camera
    so the solution to your problem is ensuring that your player controller script actually defines what it needs and exposes this to the inspector
     
    Joe-Censored likes this.
  8. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    this is what my code looks like is it right? and if not could you give me the right code
     

    Attached Files:

  9. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    have you saved your changes to the code in whatever editor you are using? make sure this is actually what is saved and not just unsaved changes to the script
     
  10. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    yes i saved it any ideas?
     
  11. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    want me to link you the tutorial so you can see what im trying to do?
     
  12. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    are there any errors in the console in unity?
     
  13. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    yes i dont know what its detecting in error though
     

    Attached Files:

    • the.png
      the.png
      File size:
      27.8 KB
      Views:
      262
  14. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    this is the full code
     

    Attached Files:

    • save.png
      save.png
      File size:
      11.1 KB
      Views:
      261
  15. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    well those are compiler errors with your script, your script cant be compiled to begin with, thus the inspector cant react to anything you changed in the script
     
  16. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    how do i fix it?
     
  17. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    You define a Start Method, methods always follow the following layout:

    <return Type> <function name>(<function parameters>)
    {
    <the function body, defines what your function is executing>
    }

    if you take a look at lines 11 and 12 you see:

    void Start()
    }

    here is a { missing at the start of your function body
     
  18. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    the error code you have above also details where you can find the error:
    they point out there is a problem with line 11 and a problem with line 17
    in line 11 is the problem that a } is read while not expected (because the { is missing), automaticly the system assumed a ; is missing tho in your case its the {
    in line 17 is the problem that you have ended up with more } than {

    thats what the error messages are trying to tell you
     
    Joe-Censored likes this.
  19. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    ok i fixed 11 but 17 is still there if i remove it or change it what do i do?
     
  20. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    there shouldnt be an error at line 17 any more if you fixed line 11/12

    the error in line 17 is simply that it found code after what should have been the last }, thus the error in line 17 is just caused by the one in line 11/12, that missed a { and thus makes the system think that the following } closes an earlier {

    if you fixed the first error everything should be fixed
     
  21. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    i fixed them but its still there
     
  22. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    this is what it looks like
     

    Attached Files:

  23. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    no as I said, there is a { missing!
    the function body always begins with a { and ends with a }
    you are not missing a ;
    the system just thinks you are missing a ; because it is more likely that you forget to end a line than that you forget to start a body^^

    just replace the ; with a { to follow the basic function syntax i described earlier:



    in other words, right now you have:
    Code (CSharp):
    1. void Start()
    2. }
    but you need it to actually have a { to follow the syntax:
    Code (CSharp):
    1. void Start()
    2. {
    3. }
     
  24. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    it just added more errors
     
  25. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    it shouldnt have, can you post a screenshot of your code again?
     
  26. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38

    this is the video i was following
     
  27. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    ok i will
     
  28. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
     

    Attached Files:

    • t.png
      t.png
      File size:
      12.3 KB
      Views:
      258
  29. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    did i do it wrong?
     
  30. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    oh, you replaced the last } with a { at some point

    the symbol in the last line must be a }, it closes the { from line 6

    how the parenthesis in c# work:
    on a ( always follows a ), and same for { and }
    you cant have unclosed opening parenthesis, and you cant close anything you havent opened yet^^
     
  31. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    i almost did it how do i remove this?
     

    Attached Files:

    • a.png
      a.png
      File size:
      159.4 KB
      Views:
      253
  32. TheNightglow

    TheNightglow

    Joined:
    Oct 1, 2018
    Posts:
    201
    you renamed your class half way through this thread^^

    in your first post it was still called "Playercontroller"
    now it is called "player"

    for any Monobehaviour class (as in attachable components) the unity file must be named like the Monobehaviour class inside it

    either rename the class name back to what it was before or change the file name of the script to the new class name
     
  33. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    oh it worked thanks
     
  34. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    and the player camera is there now thank you so much you dont even know how much you have helped me
     
  35. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'd recommend spending some time with C# specific tutorials. Most Unity tutorials have to assume a basic understanding of C# syntax. Unity uses C#, but C# is not created by Unity. In fact Microsoft created and primarily maintains C#.

    I say this because primarily the problems you're running into are basic C# syntax issues, not even Unity related. You'll have a lot easier time with learning Unity if you already know C#, instead of trying to learn both at the same time.
     
    rileydj2009 likes this.
  36. rileydj2009

    rileydj2009

    Joined:
    Apr 20, 2021
    Posts:
    38
    yeah