mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-30 13:07:10 +01:00
added Ready, NameChange, LobbyTitleChange
Added the function "AuthHost" (lobby.cs) )which can be used to check if the request comes from a host
This commit is contained in:
@@ -1,9 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Lobby : MonoBehaviour
|
||||
using Mirror;
|
||||
using TMPro;
|
||||
public class Lobby : NetworkBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public List<LobbyPlayer> LobbyPlayers = new List<LobbyPlayer>();
|
||||
|
||||
[SyncVar(hook = "ChangeTitle")]
|
||||
[SerializeField] private string lobbyTitle;
|
||||
|
||||
public bool AuthHost(LobbyPlayer player)
|
||||
{
|
||||
if(LobbyPlayers.IndexOf(player) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetTitle(LobbyPlayer player, string text)
|
||||
{
|
||||
if (AuthHost(player))
|
||||
{
|
||||
lobbyTitle = text;
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterPlayer(LobbyPlayer player)
|
||||
{
|
||||
LobbyPlayers.Add(player);
|
||||
}
|
||||
|
||||
public void ChangeTitle(string oldTitle, string newTitle)
|
||||
{
|
||||
GameObject.Find("title").GetComponent<TextMeshProUGUI>().text = newTitle;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user