mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-02-24 11:17:11 +00:00
spawning can be paused, and spawn interval can be configured
This commit is contained in:
parent
d5e35ec745
commit
3e89f57747
1 changed files with 33 additions and 3 deletions
|
@ -9,15 +9,26 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
public class SpawnManager : MonoBehaviour
|
||||
{
|
||||
public static SpawnManager Instance { get; private set; }
|
||||
|
||||
List<Transform> m_spawnPositions = new List<Transform>();
|
||||
GameObject m_container;
|
||||
public bool spawnPlayerWhenConnected = true;
|
||||
|
||||
public bool spawnPlayerWhenConnected = true;
|
||||
public bool IsSpawningPaused { get; set; } = false;
|
||||
public float spawnInterval = 4f;
|
||||
float m_lastSpawnTime = 0f;
|
||||
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
this.InvokeRepeating(nameof(UpdateSpawnPositions), 1f, 1f);
|
||||
this.InvokeRepeating(nameof(SpawnPlayers), 1f, 3f);
|
||||
this.InvokeRepeating(nameof(RepeatedMethod), 1f, 1f);
|
||||
Player.onStart += OnPlayerConnected;
|
||||
}
|
||||
|
||||
|
@ -44,6 +55,25 @@ namespace SanAndreasUnity.Behaviours
|
|||
return null;
|
||||
}
|
||||
|
||||
void RepeatedMethod()
|
||||
{
|
||||
if (!NetStatus.IsServer)
|
||||
return;
|
||||
|
||||
this.UpdateSpawnPositions();
|
||||
|
||||
if (this.IsSpawningPaused)
|
||||
return;
|
||||
|
||||
if (Time.time - m_lastSpawnTime >= this.spawnInterval)
|
||||
{
|
||||
// enough time passed
|
||||
m_lastSpawnTime = Time.time;
|
||||
this.SpawnPlayers();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UpdateSpawnPositions()
|
||||
{
|
||||
if (!Loader.HasLoaded)
|
||||
|
|
Loading…
Add table
Reference in a new issue