Search Unity

How to disable SpriteRenderer for one player and not others

Discussion in 'Multiplayer' started by Groone, Feb 20, 2019.

  1. Groone

    Groone

    Joined:
    Mar 17, 2018
    Posts:
    7
    Hello, I'n my 2D project I have a bunch of static structures with roofs. When a player goes into the structure I want the roof that covers the player to set the SpriteRenderer to disabled only for that player. The roof is essentially a sprite with a Collider2D set up as a trigger.

    I thought that using (in a nutshell)

    if (isClient){
    spriterender.enabled = off;
    }

    would work but it turns off the renderer for everyone, so I was trying to figure out how to use network id to turn it off for only one person. I'm at a loss. I know it's simple but for somereason I can't see it.

    Thank you for any help. It's much appreciated.:)
     
  2. dontdiedevelop

    dontdiedevelop

    Joined:
    Sep 18, 2018
    Posts:
    68
    Use NetworkBehaviour.netId
    To get player object use NetworkServer.FindLocalObject