Hey guys. I’m 100% new to doing a multiplayer game and I’ve been having some issues. Specifically, I have two cameras attached to my player controller. One is purely for sight, while the other is for rendering the weapon view. Both are attached to children. I’m trying to activate both of them on a player’s spawn. This poses problems when I try to do a GetComponent as it only enables one. GetComponentsInChildren doesn’t seem to work either, as it says .enabled isn’t allowed with Cameras in Unity. I tried creating a separate script to activate it but that wasn’t really working either. Furthermore, if I leave the component active prior to a player spawning, it is active for all players (Every player in game sees the hands/gun of every other player in game).
For some reason, the actual camera view is working fine, but the weapon camera is not. I have attempted attaching the weapon camera to a separate child and activating it with a transform.find(weaponcamera).gameObject.SetActive(true);. This succeeding in activating the camera, but reproduced the problem of everyone seeing it. Here’s what I have so far. Thanks!
void OnJoinedRoom () {
Debug.Log ("JOINEDROOM");
SpawnSpot mySpawnspot = spawnSpots [Random.Range (0, spawnSpots.Length)];
GameObject Player = PhotonNetwork.Instantiate("PlayerController", mySpawnspot.transform.position, mySpawnspot.transform.rotation, 0) ;
Player.GetComponent<PlayerInput>().enabled = true;
Player.GetComponent<PhotonView>().enabled = true;
Player.GetComponentInChildren<Camera>().enabled = true;
}
}