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. Dismiss Notice

Camera ignore certain objects?

Discussion in 'Scripting' started by StickyKeyStudios, Dec 31, 2014.

  1. StickyKeyStudios

    StickyKeyStudios

    Joined:
    Jun 23, 2014
    Posts:
    33
    Is there a way to specify gameobjects for the camera to ignore? I know you can set layers to each of these objects, but if I HAVE to do layers is it possible to set the layer for each gameobject locally to the network player?
    For player 1 Apple's layer would be 8, while for player 2 Apple's layer would be 9?

    Thanks
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Sure

    Code (csharp):
    1.  
    2. void Start()
    3. {
    4.     gameObject.layer = Network.isServer ? 8 : 9;
    5. }
    6.  
     
  3. StickyKeyStudios

    StickyKeyStudios

    Joined:
    Jun 23, 2014
    Posts:
    33
    Could you explain to me what you did?
     
  4. StickyKeyStudios

    StickyKeyStudios

    Joined:
    Jun 23, 2014
    Posts:
    33
    I looked up the operator ?: and I don't think it's 100% what I need. My game is a first person styled game and each player's camera is on the player model. Where the camera is position players see the inside of their body because the camera is in it, the logical solution to this is do what almost every first person game does - make the camera not render the player's body, only render everyone else's body.

    I need a "system" to be able to let players know what layers they should and shouldn't be rendering to apply this effect.

    Also, do I need 1 layer for each player or is there a much better solution to going about with this?
     
  5. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Why don't you just delete the player model if the camera belongs to the player? That's the more common approach. If a spawning player is remote then spawn a full player model otherwise just spawn a camera.

    If you really need/want to use layers then all you need are two. One for "me" and one for "not me". What goes in those layers will differ from player to player but the concept is the same across the board.

    To answer your other question - ? is a ternary operator and is more or less just a method for condensing an if-else statement to one line. I could also do this
    Code (csharp):
    1.  
    2. if (Network.isServer)
    3.     gameObject.layer = 8;
    4. else
    5.     gameObject.layer = 9;
    6.