using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Mirror; public class CellSpawner : NetworkBehaviour { public GameObject prefab; public float spawnTime; private int _capacity; private CustomNetworkManager _networkManager; private GameObject _instance; private bool _spawnStarted = false; private float _timer; void Start() { if (!isServer) return; _capacity = _networkManager.maxConnections; Console.WriteLine(_capacity); SpawnPref(); } void FixedUpdate() { if (!isServer || _capacity <= 0) return; if (_instance == null && _spawnStarted == false) { _spawnStarted = true; } if (_spawnStarted) { _timer += Time.fixedDeltaTime; } if (_timer >= 10) { _timer = 0; SpawnPref(); } } // IEnumerator RespawnTimer() // { // spawnStarted = true; // yield return new WaitForSeconds(); // SpawnPref(); // } void SpawnPref() { _instance = Instantiate(prefab, transform.position + transform.up * 1.2f, Quaternion.identity); //* 1.8f NetworkServer.Spawn(_instance); _spawnStarted = false; _capacity--; } }