hello, I’m fairly new to unity, and I’ve been making a multiplayer game. at one point i had a glitch and i had to force restart unity. once i did a few things changed and i think i got everything back to the right spot but my character will not spawn once they enter the room (VIA photon networking) I’ve narrowed it down to being something to do with my list, called chatMessages and the RPC attached to it. could someone please help me find my error?
CODE:
usingUnityEngine;
usingSystem.Collections.Generic;
publicclassNetworkManager : MonoBehaviour {
boolconnecting = false;
List chatMessages;
intmaxChat = 5;
stringmessage = “Chat”;
voidStart(){
PhotonNetwork.player.name = PlayerPrefs.GetString (“user”, “Zoosmell”);
chatMessages = newList ();
}
voidOnDestroy() {
PlayerPrefs.SetString (“user”, PhotonNetwork.player.name);
}
publicvoidAddChat (stringm) {
GetComponent ().RPC (“AddChat_RPC”, PhotonTargets.AllBuffered, m);
}
[RPC]
voidAddChat_RPC (stringm) {
while (chatMessages.Count >= maxChat) {
chatMessages.RemoveAt (0);
}
chatMessages.Add (m);
}
voidConnect() {
PhotonNetwork.ConnectUsingSettings (“demo V1”);
OnJoinedLobby ();
}
voidOnGUI(){
if (PhotonNetwork.connected == false && connecting == false) {
GUILayout.BeginArea(newRect(0, 0, Screen.width, Screen.height) );
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
GUILayout.Label ("Username: ");
PhotonNetwork.player.name = GUILayout.TextField(PhotonNetwork.player.name);
GUILayout.EndHorizontal();
if (GUILayout.Button (“Join Lobby”)) {
connecting = true;
Connect ();
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndArea();
}
if (PhotonNetwork.connected == true && connecting == false) {
GUILayout.BeginArea(newRect(0, 0, Screen.width, Screen.height) );
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
foreach(stringmsginchatMessages) {
GUILayout.Label(msg);
}
GUILayout.EndVertical();
GUILayout.EndArea();
GUILayout.BeginArea(newRect(0, 0, 300, Screen.height));
GUILayout.BeginVertical();
if(GUILayout.Button (“exit”)) {
Application.Quit();
}
GUILayout.BeginHorizontal();
GUILayout.Label ("Pester: ");
message = GUILayout.TextField (message);
if (GUILayout.Button (“Post”) || Input.GetKeyUp(“return”)) {
AddChat (PhotonNetwork.player.name + " says: " + message);
}
GUILayout.EndVertical();
GUILayout.EndHorizontal();
GUILayout.EndArea();
}
}
voidOnJoinedLobby() {
PhotonNetwork.JoinRandomRoom ();
}
voidOnPhotonRandomJoinFailed(){
PhotonNetwork.CreateRoom (null);
}
voidOnJoinedRoom(){
connecting = false;
SpawnMyPLayer ();
}
voidSpawnMyPLayer() {
AddChat (PhotonNetwork.player.name + " joined the game");
GameObjectMyPLayerGo = (GameObject)PhotonNetwork.Instantiate (“FPC”, Vector3.zero, Quaternion.identity, 0);
((MonoBehaviour)MyPLayerGo.GetComponent(“FPSInputController”)).enabled = true;
((MonoBehaviour)MyPLayerGo.GetComponent(“CharacterMotor”)).enabled = true;
((MonoBehaviour)MyPLayerGo.GetComponent(“MouseLook”)).enabled = true;
MyPLayerGo.transform.FindChild (“Main Camera”).gameObject.SetActive (true);
}
}