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 [NOOB] Disable GameObject for every other client except local

Discussion in 'Multiplayer' started by asdfasdf234, Jun 20, 2016.

  1. asdfasdf234

    asdfasdf234

    Joined:
    Nov 27, 2015
    Posts:
    70
    Hi!
    I have Player Prefab and Player Camera as separate GameObjects. So first I spawn Player Prefab and disable components if the client is not localPlayer with this code:

    if (!isLocalPlayer)
    {
    for (int i = 0; i < componentsToDisable.Length; i++)
    {
    componentsToDisable.enabled = false;

    }

    }

    this works fine exactly as intended, so now from one of the Player Prefab scripts i call a function to instantiate Player Camera now here's my problem how do I set this camera to have local authority and disable all of its components if its not local.

    I tried putting Network Identity on Camera and checking "Local Player Authority". On the script then i tried to Check and disable components the same way as on Player Prefab

    if (!isLocalPlayer)
    {
    for (int i = 0; i < componentsToDisable.Length; i++)
    {
    componentsToDisable.enabled = false;

    }

    }

    but it doesn't work :( (it does not recognize this Gameobject as localPlayer)