- Home /
Question by
1234filip · Jun 22, 2017 at 10:34 AM ·
networkingspawninghud
Network Manager Disabling parts of the HUD
Hey!
I'm using the network manager and I have a crosshair on my scene. How do I enable it on spawn and disable it on disconnect? This is the code that is attached to the player prefab.
using UnityEngine;
using UnityEngine.Networking;
public class PlayerSetup : NetworkBehaviour {
[SerializeField]
Behaviour[] componentsToDisable;
Camera sceneCam;
void Start()
{
if (!isLocalPlayer)
{
for(int i = 0; i < componentsToDisable.Length; i++)
{
componentsToDisable[i].enabled = false;
}
} else
{
sceneCam = Camera.main;
if(sceneCam != null)
{
sceneCam.gameObject.SetActive(false);
}
}
}
void OnDisable()
{
if(sceneCam != null)
{
sceneCam.gameObject.SetActive(true);
}
}
}
The sceneCam is the lobby cam. The componentsToDisable are the audio listener of the player, the camera and the Fps controller script.
Comment
Your answer
Follow this Question
Related Questions
Networking Question: Spawning selectively / on only one client. 1 Answer
How to Instance GameObjects Over the Pun Network 2 Answers
Spawning bullets on host and client Networking 1 Answer
What is the best method for handling references to objects on Clients from a Network.Spawn? 0 Answers
Does the client keep the order of object spawning? 0 Answers