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 _maxConnections; private CustomNetworkManager _networkManager; private GameObject _instance; private bool _spawnStarted = false; private float _timer; void Start() { if (!isServer) return; _networkManager = NetworkManager.singleton.GetComponent(); _maxConnections = _networkManager.maxConnections; SpawnPref(); } void FixedUpdate() { if (!isServer || _maxConnections <= 0) return; if (_instance == null && _spawnStarted == false) { _spawnStarted = true; } if (_spawnStarted) { _timer += Time.fixedDeltaTime; } if (_timer >= 10) { _timer = 0; SpawnPref(); } } void SpawnPref() { _instance = Instantiate(prefab, transform.position + transform.up * 1.2f, Quaternion.identity); //* 1.8f NetworkServer.Spawn(_instance); _spawnStarted = false; _maxConnections--; } }