43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using System;
|
|
using Unity.Netcode;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace DefaultNamespace
|
|
{
|
|
public class StartGameButton : MonoBehaviour, IPointerClickHandler
|
|
{
|
|
#if UNITY_EDITOR
|
|
[SerializeField] private SceneAsset sceneAsset;
|
|
|
|
private void OnValidate()
|
|
{
|
|
sceneName = sceneAsset.name;
|
|
}
|
|
#endif
|
|
|
|
[SerializeField, HideInInspector] private string sceneName;
|
|
|
|
private void Awake()
|
|
{
|
|
NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnected;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
NetworkManager.Singleton.OnClientConnectedCallback -= OnClientConnected;
|
|
}
|
|
|
|
private void OnClientConnected(ulong obj)
|
|
{
|
|
gameObject.SetActive(NetworkManager.Singleton.IsServer);
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
NetworkManager.Singleton.SceneManager.LoadScene(sceneName, LoadSceneMode.Single);
|
|
}
|
|
}
|
|
} |