Files
PenguinsTwoChase/Assets/Scripts/GameState/GameStateSpawner.cs

34 lines
909 B
C#

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);
}
}
}