- Home /
how to make game start when both the players are connected?
i am working on a multiplayer online game, here player A creates a room and player B joins the room and plays with him, but i want game to be paused until both a and b are connected. but for somereason i am not able to make my script read if both players available in scene.
private bool p1ready,p2ready;
void Update() {
PlayerInit();
PlayerCheck();
}
void PlayerInit() {
if(GameObject.Find("player1(clone)").activeself) p1ready = true;
if(GameObject.Find("player2(clone)").activeself) p2ready = true;
}
void PlayerCheck() {
if(p1ready && p2ready) Time.timeScale = 1.0f;
else Time.timeScale = 0.0f;
}
hmm...I'd be pretty hesitant about using Time.timeScale.
In our game we had a menu scene, and the game creator was the only one that could start (it sent a message to other players...an RPC method). It could take a couple of seconds for players to spawn in I suppose, but in that time there's no danger. That was using PUN, but I'm sure you can do the same with unity networking. Here http://docs.unity3d.com/$$anonymous$$anual/net-RPCDetails.html
I'm putting this as a comment though, because I don't like waiting for scenes to load.
What isn't working about this? You say that "not able to make my script read if both players available". Why not? Are you not able to find the players in the scene? Or are you not able to detect their "readyness". You have some detective work to do and we can't help you.
Your answer
Follow this Question
Related Questions
How to load the second online scene in UNET? 0 Answers
Network Game Player reference 0 Answers
How would you set up a Lobby Scene? 1 Answer
How do i animate threw network 1 Answer
Connect to non-unity server with LLAPI 0 Answers