Added game state and network client
This commit is contained in:
31
Assets/Scripts/GameState/GameStateController.cs
Normal file
31
Assets/Scripts/GameState/GameStateController.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace PashaBibko.PenguinChase.GameState
|
||||
{
|
||||
public enum GameState
|
||||
{
|
||||
Lobby,
|
||||
Playing,
|
||||
}
|
||||
|
||||
public class GameStateController : NetworkBehaviour
|
||||
{
|
||||
private static GameStateController sInstance;
|
||||
|
||||
[SerializeField] private NetworkVariable<GameState> GlobalState = new();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Stops overlapping instances
|
||||
if (sInstance is not null)
|
||||
{
|
||||
Debug.LogError($"Multiple of [{nameof(GameStateController)}] cannot exist.");
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
sInstance = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/GameState/GameStateController.cs.meta
Normal file
3
Assets/Scripts/GameState/GameStateController.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ad1829714634ac1ab8f480e54fe27e9
|
||||
timeCreated: 1779273141
|
||||
33
Assets/Scripts/GameState/GameStateSpawner.cs
Normal file
33
Assets/Scripts/GameState/GameStateSpawner.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace PashaBibko.PenguinChase.GameState
|
||||
{
|
||||
public class GameStateSpawner : MonoBehaviour
|
||||
{
|
||||
private static GameStateSpawner sInstance;
|
||||
|
||||
[Header("References")]
|
||||
[SerializeField] private GameObject GameStateControllerPrefab;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Stops overlapping instances
|
||||
if (sInstance is not null)
|
||||
{
|
||||
Debug.LogError($"Multiple of [{nameof(GameStateSpawner)}] cannot exist.");
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
sInstance = this;
|
||||
}
|
||||
|
||||
public static void CreateNetworkGameStateController()
|
||||
{
|
||||
GameObject go = Instantiate(sInstance.GameStateControllerPrefab);
|
||||
go.GetComponent<NetworkObject>().Spawn();
|
||||
DontDestroyOnLoad(go);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/GameState/GameStateSpawner.cs.meta
Normal file
3
Assets/Scripts/GameState/GameStateSpawner.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 354f068d231a4ca0a1ccd0560f1836d5
|
||||
timeCreated: 1779273552
|
||||
Reference in New Issue
Block a user