Hello,
I am currently working on a multiplayer project with Unity Network. I would like to create a manuel lobby. I tried to solve what i want to do with ready lobby system but i couldn’t overcome on some points. Here is what i want to do;
→ On click find a “multiplayer match button”, first of all it will search for a match and if it can’t find it, it will create a room(I found the part of creating room), if it finds, it will join the room.
→ These rooms will be invisible(I mean they will not be seen on lobby screen. There will be only player’s icon stand in the lobby and when the other player comes, other players icon will stand next to this player) and max player will be two.
→ After the game starts, the joining to these rooms will be closed.
How can i create this part with Unity network?
I have actually created this lobby part with photon network. But i decided to change my network service from photon network to unity network due to latency and lag problems that i live through with photon. I will be waiting for your answers. Thank you.
1 Like
Hello again,
I have kind of found something which is useful for me. It is SimpleMatchMaker script which is provided by Unity in the documents. I am currently working on it since last night and i haven’t figured out some parts. It seems it’s not flexible or i couldn’t find what i am looking for. For instance;
→ I create a room and i can join that room with the other player. I can set the room name randomly and i can join that room without typing its name. But, i can’t close participation to that room and besides, i can’t direct the screen of host player to game screen. The participator can be directed by the way. The prefabs of player or the enemies cannot be created in the game screen even if the participator is being directed to there. The questions are;
→ How can i close the participation to that room?
→ How can i get the players’ ids to create them in the game screen?
→ Hoe can i direct host player screen to game screen?
→ How can i get the game id?
I just made this video and it’s EXACTLY what you want ;D @mods: Sorry if I seem spammy with this video, but it’s just all-too-relevant.
2 Likes
Thank you so much dylanh7244! That was exactly what i was looking for. You are great! I have two questions;
→ How can i start the game after the player joins the lobby?
→ How can i set the player “Ready” boolean to true? Actually i have tried something for this, but it didn’t work. " this.matchMaker.GetComponent().readyToBegin=true;" It didn’t work because lobby player appears on lobby after this code is called. How can i get this work?
I didn’t get very far past that video yet
but it should IN THEORY start automatically when 1) You reach the “minimum players” to start the game 2) If you reach the minimum players AND everyone readies up, it should auto start. I think.
In NetworkLobbyPlayer script, at Start, I auto ready up with:
if (this.isLocalPlayer && !this.readyToBegin)
{
Debug.Log(“[LobbyPlayer] Player #” + this.playerControllerId + " clicked READY!");
SendReadyToBeginMessage();
}
God this took me forever to find too. I’m about at the same area as you. If you progress further, let me know.
1 Like
This seems better way then mine. I have prepared something else before i see this answer
Here it is;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
public class MyLobby:NetworkLobbyManager{
public static float countTimer;
void Update()
{
if(countTimer==0)
return;
if(Time.time>countTimer)
{
countTimer=0;
ServerChangeScene(playScene);
}
else
{
Debug.Log("Countingdown"+(countTimer-Time.time));
}
}
//This script is called from Lobby Player prefabs.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class NetworkViewM : NetworkBehaviour{
public static bool started Counting;
void Start()
{
startedCounting=true;
NetworkViewn View= gameObject.GetComponent<NetworkView>();
if(!isLocalPlayer){
gameObject.tag="otherPlayer";
gameObject.GetComponent<NetworkLobbyPlayer>().readyToBegin=true;
}else
{
gameObject.tag="myPlayer";
gameObject.GetComponent<NetworkLobbyPlayer>().readyToBegin=true;
Debug.Log("LOCALPLAYERTRUE");
}
}
}
it starts counting from another script. After the both player appears on lobby, game starts in five seconds. I did this because when the player joins the lobby, its lobby player object seems too late on the lobby.
And here is the counting script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Counter:MonoBehaviour{
public Text counter;
public static float counter Counter;
public static bool countDownStarted;
void Start()
{
counterCounter=5;
countDownStarted=true;
}
void Update(){
counter.text=counterCounter.ToString();
if(GameObject.FindWithTag("otherPlayer") !=null&&GameObject.FindWithTag("myPlayer") !=null)
{
if(countDownStarted)
{
counterCounter=5;
StartCoroutine(countDown());
countDownStarted=false;
}
}else
{
counterCounter=5;
countDownStarted=true;
StopCoroutine(countDown());
}
}
IEnumerator countDown()
{
while(true)
{
yield return new WaitForSeconds(1);
if(counterCounter>=1)
{
counterCounter-=1;
yield return null;
}else
{
counterCounter=0;
MyLobby.countTimer=10;
yield break;
}
Debug.Log("COUNTER:"+counterCounter);
}
}
}
The way that i use is a long version as it seems but it works great. I didn’t do all tests on it but for now, it seems there is no error.
Is there anything like this for Photon?