- Home /
Unity / Photon Networking Question
Having some problems and wondering what I might be doing wrong.
Basic set up is as follows:
Game starts in MainMenu scene, and have a GameObject with 'Connect.cs' and 'NetworkManager.cs' scripts on it.
'Connect.cs' handles connecting to Photon and joining/creating rooms, and also has a DontDesroyOnLoad so the GameObject containing these 2 scripts won't be destroyed.
'NetworkManager.cs' loads the MainScene scene within the OnJoinedRoom function and then tries to find a 'PlayerTracker.cs' script that is placed on a GameObject called 'Scripts' that loads in the MainScene. The idea being that it would check the PlayerTracker.cs script to see if Player1Exists bool is false, and if so, to instantiate Player 1, etc.
The problem I'm having is I'm getting a null reference when it tries to find the GameObject called 'Scripts', but everything appears to be spelled correctly, and the 'Scripts' GameObject definitely exists in the MainScene and holds the PlayerTracker.cs script.
Any ideas what is going wrong here?
Code on NetworkManger is something like follows:
OnJoinedRoom() {
PhotonNetwork.LoadLevel("MainScene");
playerTracker = GameObject.Find("Scripts").GetComponent <"PlayerTracker>();
}
*Note the " mark just before PlayerTracker was just added for this question so the text would appear properly, and doesn't appear in the actual code.