сростил проекты
This commit is contained in:
1 parent
a4573f2d12
commit
dfd44aa129
684 files changed
+152796
-67
No files matched your search
@@ -0,0 +1,49 @@
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class BonusSpawner : MonoBehaviour
|
||||
{
|
||||
[Header("Настройки спавна")]
|
||||
public GameObject[] bonusPrefabs;
|
||||
[Tooltip("Минимальное и максимальное время между спавнами бонусов")]
|
||||
public Vector2 spawnInterval = new Vector2(10f, 20f);
|
||||
[Tooltip("Как далеко впереди игрока спавнить бонус")]
|
||||
public float spawnDistance = 100f;
|
||||
|
||||
private Transform _playerTransform;
|
||||
|
||||
void Start()
|
||||
{
|
||||
StartCoroutine(SpawnBonusRoutine());
|
||||
}
|
||||
|
||||
IEnumerator SpawnBonusRoutine()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
float waitTime = Random.Range(spawnInterval.x, spawnInterval.y);
|
||||
yield return new WaitForSeconds(waitTime);
|
||||
|
||||
if (bonusPrefabs.Length == 0 || RoadManager.Instance == null || RoadManager.Instance.playerTransform == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float spawnX = RoadManager.Instance.GetRandomLaneX();
|
||||
float spawnZ = RoadManager.Instance.playerTransform.position.z + spawnDistance;
|
||||
Vector3 spawnPosition = new Vector3(spawnX, 0.5f, spawnZ);
|
||||
|
||||
GameObject bonusPrefab = bonusPrefabs[Random.Range(0, bonusPrefabs.Length)];
|
||||
|
||||
GameObject bonus = SimpleObjectPool.Instance.Get(bonusPrefab, spawnPosition, Quaternion.identity);
|
||||
|
||||
BonusPickup pickup = bonus.GetComponent<BonusPickup>();
|
||||
if (pickup != null)
|
||||
{
|
||||
pickup.Init(bonusPrefab);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user