Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

LAN, 2 clients same camera, why?

Discussion in 'Multiplayer' started by maronas223, Mar 25, 2020.

  1. maronas223

    maronas223

    Joined:
    Nov 9, 2019
    Posts:
    3
    Hello,
    I have some problems with my unity project. I made LAN game, and its working fine when its only one camera in scene... But when I put camera in player prefab and spawn 2 players(one host and another join player) I see that camera is same in both screens...Controls working fine in both screens, different to each other. Any solutions?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Why do you need 2 cameras when each client only needs their 1 camera?

    But if you want both cameras, you'll need to disable all the cameras you don't want to use on each client, or start with all the cameras disabled and only enable the camera the client wants to use. I'd probably do it on the Player GameObject after checking if isLocalPlayer is true. I'm assuming this is Unet or Mirror.
     
  3. maronas223

    maronas223

    Joined:
    Nov 9, 2019
    Posts:
    3

    Thanks for reply.
    No, I need one camera for player, but when 2 players spawned in both players is a same camera, same view. Players walk normaly, but see same view, and when looking around with mouse in both screen same view. Maybe you know how to fix it?
     
  4. maronas223

    maronas223

    Joined:
    Nov 9, 2019
    Posts:
    3
    If somebody will have same problem to my I found solution. In script make public gameObject, add the camera from your prefab to it. Then disable camera in prefab by uncheck place marked in my SS.
    Then in script write:

    Code (CSharp):
    1.     void Start()
    2.     {
    3.         if (isLocalPlayer)
    4.         {
    5.             CameraY.SetActive(true);
    6.         }
    7.     }
    Where CameraY is gameObject camera from prefab. I hope will help somebody!! :)
     

    Attached Files:

    Janne-L and Joe-Censored like this.