- Home /
 
How do I make a Game Object invisible?
Hi, I'm working on a multiplayer project and I want to make it so you can't see certain objects such as your player model but you can see others. I can't do different layers because then all players will only see whats suppose to be seen in first person. How would I go about doing this? Thanks!
Another way to say what I mean is I'm using the layer trick to make the guns not clip through the walls. How can I make it so I can't see the other players gun through the wall. I tried this but It didn't work public class PlayerSetup : NetworkBehaviour { [SerializeField] Behaviour[] componentsToDisable; GameObject[] gunl; GameObject[] mp; void Start () {
         if (!isLocalPlayer)
         {
             gunl = GameObject.FindGameObjectsWithTag("gun"); 
             mp = GameObject.FindGameObjectsWithTag("mp");
             for (int i = 0; i < componentsToDisable.Length; i++)
             {
                 componentsToDisable[i].enabled = false;
             }
             for (int a = 0; a <= gunl.Length; a++)
             {
                     gunl[a].layer = 0;
 
             }
 
             for (int c = 0; c <= mp.Length; c++)
             {
                 mp[c].layer = 0;
                 
             }
         }
     }
 }
 
 
              you can make gameobject invisible like this. Give different tags to player and other players
  GameObject player = GameObject.FindGameObjectWithTag ("player");
     player.GetComponent<$$anonymous$$eshRenderer>().enabled = false;
 
     GameObject[] otherPlayers = GameObject.FindGameObjectsWithTag ("otherPlayer");
     foreach(GameObject item in otherPlayers)
     {
          item.GetComponent<$$anonymous$$eshRenderer>().enabled = true;
     }
 
                 Answer by Nick_Rizzo · Feb 10, 2016 at 09:16 AM
I found out the answer before the question got approved (like a week) sorry about that... Here's what I came up with probably works better with a loop or something but it works for me, using UnityEngine; using System.Collections; using UnityEngine.Networking;
 public class PlayerSetup : NetworkBehaviour
 {
     [SerializeField]
     Behaviour[] componentsToDisable;
     public GameObject thief;
     public GameObject gun;
     public GameObject body;
     public GameObject bottoms;
     public GameObject eyes;
     public GameObject gloves;
     public GameObject mask;
     public GameObject shoes;
     public GameObject tops;
     public GameObject mag;
     public GameObject sights;
     public GameObject bodyA;
     void Start ()
     {
 
         if (!isLocalPlayer)
         {
             for (int i = 0; i < componentsToDisable.Length; i++)
             {
                 componentsToDisable[i].enabled = false;
             }
         }
         if (isLocalPlayer)
         {
             body.layer = 28;
             bottoms.layer = 28;
             eyes.layer = 28;
             gloves.layer = 28;
             mask.layer = 28;
             shoes.layer = 28;
             tops.layer = 28;
             thief.layer = 28;
             gun.layer = 30;
             mag.layer = 30;
             sights.layer = 30;
             bodyA.layer = 30;
         }
     }
 }
 
 
              Your answer
 
             Follow this Question
Related Questions
Online Player Position 1 Answer
Multiple Cars not working 1 Answer
Visibility of objects 2 Answers
Unity editor style camera script 1 Answer
Multiplayer Support for Android 1 Answer