add unity project for networking
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user