Good day,
I am currently trying to build a 2D game using photon for multi-player. Right now i create my room and i can join it. and i get an instance that spawns my character when i join a room.
using System.Collections;
public class NetworkManager : MonoBehaviour {
// Use this for initialization
void Start () {
Connect();
}
void Connect(){
PhotonNetwork.ConnectUsingSettings ("2DMulti V0.0.1");
}
void OnGUI(){
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString());
}
void OnJoinedLobby(){
PhotonNetwork.JoinRandomRoom ();
}
void OnPhotonRandomJoinFailed(){
PhotonNetwork.CreateRoom (null);
Debug.Log ("createroom");
}
void OnJoinedRoom(){
SpawnMyPlayer ();
}
void SpawnMyPlayer(){
PhotonNetwork.Instantiate ("MyPlayer", Vector3.zero, Quaternion.identity, 0);
}
}
How can i make my second player that connects(from a different location) appear on the screen too(it works if i do it in 3d)
It looks like it should work. Maybe the created GameObject is simply not in the screen?
Start one client and the game in-Editor. In the Editor, you can check if the Hierarchy gets the “MyPlayer” game object of both players. Check for debug logs in case the game just runs into some exception.
Thank you very much both instance of the MyPlayer is there when i check in the Hierarchy and if i move one of them in my scene i see both. Now my new question is how come nothing is updated in both instance. If i play my client version, and my character moves i dont see it move in my editor. Nothing is updated.
Thanks
Check the PhotonView component on the prefab. The Observe option might be “off” or maybe it doesn’t observe anything.
In worst case the transform for 2d is actually different than the one in 3d and we can’t successfully grab the values from that. I have to admit: I didn’t explicitly test 2d game objects.
Hi,
i have included the screenshot of the settings i currently have
To answer your questions :
No errors in log
connectionStateDetailed is Joined(If I start my editor before the client i get my debug message that createroom has been executed)
My movement script works. when everything is running if i manually move my character in the scene view my client will have the change but when my movement script is executed on MyPlayer(Children) the change are not synchronising.
In that screenshot: Is “MyPlayer” selected? It seems we see “MyPlayer(Clone)” in Inspector?
I wonder how the setup is when you write “MyPlayer(Children)”. Where exactly is the script?
If it doesn’t work with the script but without, then the script will be interesting to see. I’d have a look at a repro project, if you can send one. Mail me to developer@exitgames.com and refer to this topic please. I won’t be available before Friday, so please expect a reply next week or so. We’re at the Quo Vadis in Berlin this week.