Hey.
I need some help with my NetworkManager Script. The Error is:
NullReferenceException: Object reference not set to an instance of an object
NetworkManagerStarting.SpawnMyPlayer () (at Assets/OwnScripts/NetworkManagerStarting.cs:56)
NetworkManagerStarting.OnJoinedRoom () (at Assets/OwnScripts/NetworkManagerStarting.cs:49)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1769)
NetworkingPeer:OnEvent(EventData) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1612)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:76)
using UnityEngine;
using System.Collections;
public class NetworkManagerStarting : MonoBehaviour {
public Camera standbyCamera;
GameObject mySpawnSpot;
GameObject myPlayerGO;
public bool offlineMode = false;
// Use this for initialization
void Start () {
Connect ();
}
void Update () {
}
void Connect () {
if (offlineMode) {
PhotonNetwork.offlineMode = true;
OnJoinedLobby();
} else {
PhotonNetwork.ConnectUsingSettings ("TestVersion0.0.1");
}
}
void OnGUI(){
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
}
void OnJoinedLobby() {
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed () {
PhotonNetwork.CreateRoom( null );
}
void OnJoinedRoom(){
Debug.Log ("JoinedRoom");
SpawnMyPlayer();
}
void SpawnMyPlayer() {
mySpawnSpot = GameObject.FindWithTag("Spawnspot");
Debug.Log ("Spawnspot check");
myPlayerGO = (PhotonNetwork.Instantiate ("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation,0));
if(myPlayerGO != null) {Debug.LogError("WTF?!?!?!?!"); return; }
standbyCamera.enabled = false;
Debug.Log ("fpsready");
((MonoBehaviour)myPlayerGO.GetComponent ("MouseLook")).enabled = true;
Debug.Log ("msready");
((MonoBehaviour)myPlayerGO.GetComponent ("FPSInputController")).enabled = true;
Debug.Log ("psready");
myPlayerGO.transform.FindChild ("MainCamera").gameObject.SetActive (true);
Debug.Log ("camready");
((MonoBehaviour)myPlayerGO.GetComponent ("CharacterMotor")).enabled = true;
Debug.Log ("charready");
Debug.Log ("playready");
}
}