So I’m gonna try to make the question as small as possible. I’m currently at the early stages of developing a MMO game with Unity (2D tile based game). Now I didn’t want to wait to long with the networking part to prevent difficulties, however I can’t resolve the simple ones either. So I’m here for help.
What I want is basically:
- A sign in form, simple version → an add client button
- A start server, simple version → a start server button
Setting up the server seems to work, connecting with the client seems to work too. Connecting the buttons and all that stuff works. Loading the following scene works, however it lacks a player with a camera. The default way to do it results in a faulty rotation, which is what I want to solve (and ofcourse later on I want to do input checking and database calls, but that’s not the thing I’m stuck on.
The player rotation gets reset by default, it does not instantiate the player with the prefab rotation, but it gets reset.
So I made my own C# class MyNetworkManager derived from the NetworkManager class.
When I start the server:
public void StartUpServer()
{
NetworkManager.singleton.networkPort = 7777;
NetworkManager.singleton.networkAddress = "127.0.0.1";
NetworkManager.singleton.StartServer();
}
When I start a client:
public void StartUpClient()
{
NetworkManager.singleton.networkPort = 7777;
NetworkManager.singleton.networkAddress = "127.0.0.1";
NetworkManager.singleton.StartClient();
SceneManager.LoadScene("PlayersRoom");
// This should go to the first map (later to the saved position, but for now)
}
So how do I get my player correctly added? The following code doesn’t seem to work at all:
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
{
Debug.Log("Adding player" + playerControllerId);
Network.Instantiate(playerPrefab, new Vector3(0, 0, 0), Quaternion.Euler(new Vector4(90, 0, 0, 0)), 0);
}
It’s not that easy to find a specific tutorial on this matter. Most people just explain how to use the default built in Networkmanager, they make a client and server and there they stop. I think I watched most of the youtube videos by now, but I think that code can be way more explaining then some tutorials.