Need help with Episode 6 of Making a Multiplayer Fps.

Updated on January 3, 2017 in General
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on January 1, 2017

Hi. I was working on a project and I ran into an error message that I just cant shake. Its telling me that the layer has to be in the range of [0…31] I don’t know what to do, but I do know that I’m doing something wrong. On line 35 is where I;m getting the error.

using UnityEngine;
using UnityEngine.Networking;

public class PlayerSetup : NetworkBehaviour {

[SerializeField]
Behaviour[] componentsToDisable;

[SerializeField]
string remoteLayerName = “Remote Player”;

Camera sceneCamera;

void Start ()
{

if (!isLocalPlayer)
{
for (int i = 0; i < componentsToDisable.Length; i++)
{
componentsToDisable[i].enabled = false;
}
DisableComponents();
AsssignRemoteLayer();
}
else
{
sceneCamera = Camera.main;
if (sceneCamera != null)
{
sceneCamera.gameObject.SetActive(false);
}
}
}

void AsssignRemoteLayer()
{
gameObject.layer = LayerMask.NameToLayer(remoteLayerName);
}

void DisableComponents ()
{
for (int i = 0; i < componentsToDisable.Length; i++)
{
componentsToDisable[i].enabled = false;
}
}

void OnDisable ()
{
if (sceneCamera != null)
{
sceneCamera.gameObject.SetActive(true);
}
}
}

Any help is appreciated

  • Liked by
Reply
1 on January 1, 2017

But what is the error?

on January 3, 2017

A game object can only be in one layer. The layer needs to be in the range [0…31]
UnityEngine.GameObject:set_layer(Int32)
PlayerSetup:AsssignRemoteLayer() (at Assets/PlayerSetup.cs:39)
PlayerSetup:Start() (at Assets/PlayerSetup.cs:25)

Show more replies
  • Liked by
Reply
Cancel