Question by
dededollin · May 10, 2017 at 02:06 PM ·
errorbuggame
i have some problem with this, any solution? thanks
using UnityEngine; using UnityEngine.Networking;
[RequireComponent(typeof(Player))] public class PlayerSetup : NetworkBehaviour { [SerializeField] Behaviour[] componentsToDisable;
[SerializeField]
string remoteLayerName = "RemotePlayer";
Camera sceneCamera;
/// /////////////////////////////////// fungsi untuk menembak
void Start()
{
if (!isLocalPlayer)
{
DisableComponents();
AssingmentLayer();
}
else
{
sceneCamera = Camera.main;
if (sceneCamera != null)
{
sceneCamera.gameObject.SetActive(false);
}
}
//RegisterPlayer();
}
public override void OnStartClient()
{
base.OnStartClient();
string _netID = GetComponent<NetworkIdentity>().netId.ToString();
Player _player = GetComponent<Player>();
GameManager.RegisterPlayer(_netID, _player);
}
/*void RegisterPlayer()
{
string _ID = "Player " + GetComponent<NetworkIdentity>().netId;
transform.name = _ID;
}*/
void DisableComponents()
{
for (int i = 0; i < componentsToDisable.Length; i++)
{
componentsToDisable[i].enabled = false;
}
}
void AssingmentLayer()
{
gameObject.layer = LayerMask.NameToLayer(remoteLayerName);
}
void OnDisable()//fungsi ketika kita meledak dan hancur
{
if (sceneCamera != null)//kamera akan melakukan pengulangan untuk respawn kembali
{
sceneCamera.gameObject.SetActive(true);
}
GameManager.UnRegisterPlayer(transform.name);
}
}
and here the bug : "NullReferenceException: Object reference not set to an instance of an object PlayerSetup.DisableComponents () (at Assets/Script/PlayerSetup.cs:52) PlayerSetup.Start () (at Assets/Script/PlayerSetup.cs:20)
"
Comment
Your answer
Follow this Question
Related Questions
Unity hangs when opening a project. 0 Answers
Unexpected Symbol? Socorro! 1 Answer
I keep getting pink textures 0 Answers
Unknown error 0 Answers
unity launcher greyed out. 1 Answer