2024-03-16 20:34:22 +03:00
|
|
|
using System;
|
2024-02-19 21:00:36 +03:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using Mirror;
|
|
|
|
|
|
|
|
public class CellSpawner : NetworkBehaviour
|
|
|
|
{
|
|
|
|
public GameObject prefab;
|
|
|
|
public float spawnTime;
|
2024-03-16 20:34:22 +03:00
|
|
|
private int _capacity;
|
|
|
|
|
|
|
|
private CustomNetworkManager _networkManager;
|
2024-02-19 21:00:36 +03:00
|
|
|
private GameObject _instance;
|
2024-03-16 20:34:22 +03:00
|
|
|
private bool _spawnStarted = false;
|
2024-02-19 21:00:36 +03:00
|
|
|
private float _timer;
|
2024-03-16 20:34:22 +03:00
|
|
|
|
2024-02-19 21:00:36 +03:00
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
if (!isServer) return;
|
2024-03-16 20:34:22 +03:00
|
|
|
_capacity = _networkManager.maxConnections;
|
|
|
|
Console.WriteLine(_capacity);
|
2024-02-19 21:00:36 +03:00
|
|
|
SpawnPref();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FixedUpdate()
|
|
|
|
{
|
2024-03-16 20:34:22 +03:00
|
|
|
if (!isServer || _capacity <= 0) return;
|
2024-02-19 21:00:36 +03:00
|
|
|
|
2024-03-16 20:34:22 +03:00
|
|
|
if (_instance == null && _spawnStarted == false)
|
2024-02-19 21:00:36 +03:00
|
|
|
{
|
2024-03-16 20:34:22 +03:00
|
|
|
_spawnStarted = true;
|
2024-02-19 21:00:36 +03:00
|
|
|
}
|
|
|
|
|
2024-03-16 20:34:22 +03:00
|
|
|
if (_spawnStarted)
|
2024-02-19 21:00:36 +03:00
|
|
|
{
|
|
|
|
_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);
|
2024-03-16 20:34:22 +03:00
|
|
|
_spawnStarted = false;
|
|
|
|
_capacity--;
|
2024-02-19 21:00:36 +03:00
|
|
|
}
|
|
|
|
}
|