I am following a series of tutorials as closely as I can, but I am having a problem. I think this may be the source. When I have 2 players in the scene running in different instances of the game, one is supposed to be local, and the other is supposed to be remote. however, both stay local, and it gives me the error “A game object can only be in one layer. The layer needs to be in the range [0…31]”
Here is my full script:
using UnityEngine;
using UnityEngine.Networking;
public class PlayerSetup : NetworkBehaviour {
[SerializeField]
Behaviour[] componentsToDisable;
[SerializeField]
string remoteLayerName = "RemotePlayer";
Camera sceneCamera;
void Start()
{
if (!isLocalPlayer)
{
DisableComponents();
AssignRemoteLayer();
}
else
{
sceneCamera = Camera.main;
if (sceneCamera != null)
Camera.main.gameObject.SetActive(false);
}
RegisterPlayer();
}
void RegisterPlayer()
{
string _ID = "Player " + GetComponent<NetworkIdentity>().netId;
transform.name = _ID;
}
void AssignRemoteLayer()
{
gameObject.layer = LayerMask.NameToLayer(remoteLayerName);
}
void DisableComponents()
{
for (int i = 0; i < componentsToDisable.Length; i++)
{
componentsToDisable*.enabled = false;*
}
}
void OnDisable()
{
if (sceneCamera != null)
sceneCamera.gameObject.SetActive(true);
}
}