So I m trying to make a local multiplayer fps prototype. There is a youtube video on this but couldn’t find any help there:
It throws this error:
IndexOutOfRangeException: Array index is out of range.
PlayerSetup.DisableComponents () (at Assets/Scripts/PlayerSetup.cs:17)
PlayerSetup.Start () (at Assets/Scripts/PlayerSetup.cs:27)
Here is my code:
using UnityEngine;
using UnityEngine.Networking;
public class PlayerSetup : NetworkBehaviour {
[SerializeField]
Behaviour[] componentsToDisable;
[SerializeField]
string remoteLayerName = "RemotePlayer";
Camera sceneCamera;
void DisableComponents()
{
for (int i = 0; 1 < componentsToDisable.Length; i++)
{
componentsToDisable[i].enabled = false;
}
}
void Start ()
{
if (!isLocalPlayer)
{
// Disable components that should only be
// active on the player the we control
DisableComponents();
AssignRemoteLayer();
}else
{
// We are the local player: Disable the scene camera
sceneCamera = Camera.main;
if (sceneCamera != null)
{
sceneCamera.gameObject.SetActive(false);
}
}
}
void AssignRemoteLayer ()
{
gameObject.layer = LayerMask.NameToLayer(remoteLayerName);
}
void OnDisable ()
{
if (sceneCamera != null)
{
sceneCamera.gameObject.SetActive(true);
}
}