Project
This commit is contained in:
1 parent
e1a474d4ac
commit
24b1157026
164 files changed
+68527
No files matched your search
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Alchemy.Inspector;
|
||||
using Code.PassingObjects;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Code.GameplayServices
|
||||
{
|
||||
public class PassingObjectsManager : MonoBehaviour
|
||||
{
|
||||
[TabGroup("Spawn")] [SerializeField] private List<Transform> spawnPoints;
|
||||
[TabGroup("Spawn")] [SerializeField] private List<GameObject> prefabs;
|
||||
|
||||
[TabGroup("Gameplay")] [SerializeField]
|
||||
private float behindPlayerThreshold;
|
||||
|
||||
[TabGroup("Gameplay")] [SerializeField]
|
||||
private float obstacleCooldown;
|
||||
|
||||
[TabGroup("Gameplay")] [SerializeField]
|
||||
private List<PassingObjectsPreset> obstaclesPresets;
|
||||
|
||||
private List<GameObject> _spawnedObjects = new();
|
||||
public float BehindPlayerThreshold => behindPlayerThreshold;
|
||||
public static PassingObjectsManager Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void ResetObjects()
|
||||
{
|
||||
foreach (var spawnedObject in _spawnedObjects)
|
||||
{
|
||||
Destroy(spawnedObject);
|
||||
}
|
||||
_spawnedObjects.Clear();
|
||||
_timer = 0f;
|
||||
}
|
||||
public void KillChild(PassingObject child)
|
||||
{
|
||||
if (!_spawnedObjects.Contains(child.gameObject)) return;
|
||||
|
||||
_spawnedObjects.Remove(child.gameObject);
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
private float _timer;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(GameplayManager.Instance.OnPause) return;
|
||||
|
||||
_timer += Time.deltaTime;
|
||||
|
||||
if (!(_timer > obstacleCooldown)) return;
|
||||
|
||||
_timer = 0f;
|
||||
|
||||
if (prefabs.Count == 0 && obstaclesPresets.Count > 0) return;
|
||||
|
||||
var presetId = Random.Range(0, obstaclesPresets.Count);
|
||||
|
||||
_spawnedObjects.Add(
|
||||
Instantiate(
|
||||
prefabs[obstaclesPresets[presetId].prefabId1],
|
||||
spawnPoints[0].position,
|
||||
spawnPoints[0].rotation));
|
||||
_spawnedObjects.Add(
|
||||
Instantiate(
|
||||
prefabs[obstaclesPresets[presetId].prefabId2],
|
||||
spawnPoints[1].position,
|
||||
spawnPoints[1].rotation));
|
||||
_spawnedObjects.Add(
|
||||
Instantiate(
|
||||
prefabs[obstaclesPresets[presetId].prefabId3],
|
||||
spawnPoints[2].position,
|
||||
spawnPoints[2].rotation));
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class PassingObjectsPreset
|
||||
{
|
||||
public int prefabId1;
|
||||
public int prefabId2;
|
||||
public int prefabId3;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user