Hi, I’m trying to learn unity rpc calls to a simple multiplay game.
I would like to know the correct way to change level over network so people who joins my server after a change level, change to the correct scene and interact with its objects.
- I made a second scene(level);
- The server changed the scene before client connect;
- List item
!-----When client join the server he connect in first scene because he don’t got the change scene call.
- Made a LOBBY Layer before the “Real Game”;
- Wait people connect to server;
- Did a change level via RPC call;
Its ok, it change the level to everyone, BUT…
If someone join the lobby after the “change the stage rpc call”, he still don’t got the level;
[What Should I Do?]
- How I pass the level to client when he joins my server?
- When I tell him the level and find a solution to the client change the scene, when he joins the server, his “scene2” will be our same “scene 2”?
I mean, a “spawn object call” will create the object in the same scene view?
In a network gamed, theoretically people need information from the server not only about the scene, but about every object in the scene that can change during gameplay. So to answer your question “is his scene2 the same as our our scene2?” the answer is, yes, it is the same, but it may not be in the same state unless you make additional server calls to update the state of each object.
For simplicity, I’m going to assume that this function happens all by itself. In reality, you may want to combine this functionality with a larger gamestate manager or network manager.
- Create an empty gameObject called something like LevelManager, or something similar.
- Create a script on the object, call it something like LevelManagerScript.
- In the script create a function called something like GetLevelNumberFromServer(). That function should ask the server what level everyone is on. If it turns out they’re on a different level, it should call Application.LoadLevel().
- Call GetLevelNumberFromServer() where relevant. If it’s from another Script, make sure GetLevelNumberFromServer() is public.
Hope that helps. Again remember that every object that could be changed also needs to get updated. Conceptually, if there are AI enemies for example, then every enemy could have a function called GetPositionFromServer(), that checks to see where the server thinks it is and moves them there accordingly. They also need to check their life, their ammo, or whatever other variables they have. And ideally, the updates look smooth instead of jumpy, which can be quite a feat involving prediction, interpolation, etc., etc. Good luck!