Answer the question
In order to leave comments, you need to log in
How to synchronize objects when using UNET?
Hello everyone, tell me how to synchronize PlayerLobby.
There is a NetworkLobbyManager, there is a prefab LobbyPlayer, and so there is a task so that when the player clicks "Finish", the object changes. So the changes are made, but the changes are not visible from the second player.
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
namespace Assets.Scripts.Controller.MainMenu
{
public class LobbyPlayerController : NetworkLobbyPlayer
{
private Text _name;
private GameObject _status;
private GameObject _readyBtn;
private GameObject _notReadyBtn;
private GameObject _expelBtn;
[SerializeField] private Sprite[] _statusImages;
public Text Name
{
get
{
return _name;
}
}
public GameObject Status
{
get
{
return _status;
}
}
public GameObject ReadyBtn
{
get
{
return _readyBtn;
}
}
public GameObject NotReadyBtn
{
get
{
return _notReadyBtn;
}
}
public GameObject ExpelBtn
{
get
{
return _expelBtn;
}
}
public Sprite[] StatusImages
{
get
{
return _statusImages;
}
}
public void Awake()
{
_name = transform.Find("PlayerName").gameObject.GetComponent<Text>();
_status = transform.Find("PlayerStatus").gameObject;
_readyBtn = transform.Find("PlayerReadyBtn").gameObject;
_notReadyBtn = transform.Find("PlayerNotReadyBtn").gameObject;
_expelBtn = transform.Find("PlayerExpelBtn").gameObject;
}
void Start()
{
Name.text = GetInstanceID().ToString();
if (isLocalPlayer)
{
ReadyBtn.SetActive(true);
}
if (isServer)
{
ExpelBtn.SetActive(true);
}
}
public void OnClickReady()
{
ReadyBtn.SetActive(false);
NotReadyBtn.SetActive(true);
Status.GetComponent<Image>().sprite = StatusImages[1];
}
public void OnClickNotReady()
{
NotReadyBtn.SetActive(false);
ReadyBtn.SetActive(true);
Status.GetComponent<Image>().sprite = StatusImages[0];
}
public override void OnClientEnterLobby()
{
base.OnClientEnterLobby();
transform.SetParent(GameObject.FindGameObjectWithTag("Respawn").transform);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question