NullReferenceException: Object reference not set to an instance of an object
i try to enable player camera after his spawn
void SpawnMyPlayer (){
SpawnSpot mySpawnSpot = spawnSpots [Random.Range (0, spawnSpots.Length)];
GameObject myPlayerGO =(GameObject)PhotonNetwork.Instantiate ("PlayerController", mySpawnSpot.transform.position,mySpawnSpot.transform.rotation, 0);
standbyCamera.SetActive(false);
((MonoBehaviour)myPlayerGO.GetComponent("FPSInputController")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("CharacterMotor")).enabled = true;
myPlayerGO.GetComponentInChildren<Camera>().enabled = true;
myPlayerGO.GetComponentInChildren<AudioListener>().enabled = true;
myPlayerGO.GetComponent<CharacterController>().enabled = true;
}
but i get this error NullReferenceException: Object reference not set to an instance of an object NetworkManager.SpawnMyPlayer () (at Assets/NetworkManager.cs:53) NetworkManager.OnJoinedRoom () (at Assets/NetworkManager.cs:37) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[]) (at Assets/_Imported/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2084) NetworkingPeer:OnEvent(EventData) (at Assets/_Imported/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1885) ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[]) ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() PhotonHandler:Update() (at Assets/_Imported/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:92) all work befor this add
Your answer
Follow this Question
Related Questions
InputKey on Update with INT Counter - Camera Switch - Not working properly. 1 Answer
using cheat codes to enable a camera effect. 0 Answers
Designing a system to switch between cameras without disabling any of them 4 Answers
C# > Camera tagged MainCamera > GetComponent<[ScriptClassHere]>() returns null ? 0 Answers