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.

Unity Multiplayer Client and server use same camera

Discussion in 'Multiplayer' started by zoelee, Jun 27, 2017.

  1. zoelee

    zoelee

    Joined:
    Sep 9, 2015
    Posts:
    3
    I have a player with a camera attached to it as a child. When I start the server, the player spawns and it works perfectly. Then when a client joins the server it spawns another player, however both the host and the client can only see out of the client's camera. I am wondering what a good fix for this might be.

    I know that two players spawn, both the host and the client can only control their player. The controls and movement are working.
     
  2. TwoTen

    TwoTen

    Unity Technologies

    Joined:
    May 25, 2016
    Posts:
    1,168
    if(!isLocalPlayer)
    camera.enabled = false;
     
  3. zoelee

    zoelee

    Joined:
    Sep 9, 2015
    Posts:
    3
    Thanks for your help, but `isLocalPlayer` always returns true.
     
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,332
    If you're asking on the local player, then it should.
     
  5. TwoTen

    TwoTen

    Unity Technologies

    Joined:
    May 25, 2016
    Posts:
    1,168
    On the remote clients it should return false? meaning it will be disabled for them
     
  6. zoelee

    zoelee

    Joined:
    Sep 9, 2015
    Posts:
    3
    ok, finally got this to work. thank you for the help.
     
  7. ElSabadero

    ElSabadero

    Joined:
    Dec 7, 2018
    Posts:
    7
    I have the same problem, please tell me how you fixed it.
     
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,824
    What is wrong with the solution already posted?
     
  9. MannequinBaby

    MannequinBaby

    Joined:
    Jan 28, 2019
    Posts:
    1
    I believe at this point the previous solution has been depreciated. My editor is telling me I need to use GetComponent<camera>().
     
  10. naimish1308

    naimish1308

    Joined:
    Jul 10, 2018
    Posts:
    5
    can someone pls help on the same problem
     
  11. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,824
    "camera" in TwoTen's solution is a reference to the camera component, which you'd probably want to name something else anyways. You get a reference to it the same as getting a reference to anything (via inspector, GetComponent, etc).
     
  12. SirhotBay

    SirhotBay

    Joined:
    Feb 3, 2021
    Posts:
    8
    this.gameObject.GetComponentInChildren<Camera>().enabled = false;
     
  13. maksimchernichenko

    maksimchernichenko

    Joined:
    Oct 22, 2022
    Posts:
    3
    it works but now my client cant move
     
  14. maksimchernichenko

    maksimchernichenko

    Joined:
    Oct 22, 2022
    Posts:
    3
    where do i put the code
     
  15. maksimchernichenko

    maksimchernichenko

    Joined:
    Oct 22, 2022
    Posts:
    3
    nvm i figured it out
     
  16. E4gy

    E4gy

    Joined:
    Feb 28, 2022
    Posts:
    1
    It worked for me as followed:

    public Camera viewCam;

    void Update
    {
    if (!IsOwner) viewCam.enabled = false;
    }