папочка навёл порядок в папках
This commit is contained in:
1 parent
9374a984e6
commit
b407380203
1123 files changed
+2764
-133233
No files matched your search
@@ -0,0 +1,11 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class BonusEffect : ScriptableObject
|
||||
{
|
||||
[Tooltip("Длительность бонуса в секундах")]
|
||||
public float duration = 10f;
|
||||
|
||||
public abstract void Activate(GameObject player);
|
||||
public abstract void Deactivate(GameObject player);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd9853d2913c2c949bbc8a06d0b9ee48
|
||||
@@ -0,0 +1,82 @@
|
||||
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class BonusManager : MonoBehaviour
|
||||
{
|
||||
public static BonusManager Instance { get; private set; }
|
||||
|
||||
[Header("UI Элементы")]
|
||||
public Image bonusIcon;
|
||||
public TextMeshProUGUI bonusTimerText;
|
||||
|
||||
private BonusEffect _activeBonus;
|
||||
private float _timer;
|
||||
private GameObject _player;
|
||||
private int _lastDisplayedTime = -1;
|
||||
void Awake()
|
||||
{
|
||||
if (Instance == null) Instance = this;
|
||||
else Destroy(gameObject);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
_player = GameObject.FindGameObjectWithTag("Player");
|
||||
bonusIcon.gameObject.SetActive(false);
|
||||
bonusTimerText.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_activeBonus != null)
|
||||
{
|
||||
_timer -= Time.deltaTime;
|
||||
if (_timer <= 0)
|
||||
{
|
||||
DeactivateBonus();
|
||||
}
|
||||
else
|
||||
{
|
||||
int secondsLeft = Mathf.CeilToInt(_timer);
|
||||
if (secondsLeft != _lastDisplayedTime)
|
||||
{
|
||||
_lastDisplayedTime = secondsLeft;
|
||||
bonusTimerText.text = secondsLeft.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ActivateBonus(BonusEffect bonus)
|
||||
{
|
||||
if (_activeBonus != null)
|
||||
{
|
||||
DeactivateBonus();
|
||||
}
|
||||
|
||||
_activeBonus = bonus;
|
||||
_timer = _activeBonus.duration;
|
||||
_lastDisplayedTime = -1;
|
||||
|
||||
_activeBonus.Activate(_player);
|
||||
|
||||
bonusIcon.gameObject.SetActive(true);
|
||||
bonusTimerText.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void DeactivateBonus()
|
||||
{
|
||||
if (_activeBonus != null && _player != null)
|
||||
{
|
||||
_activeBonus.Deactivate(_player);
|
||||
}
|
||||
_activeBonus = null;
|
||||
_timer = 0;
|
||||
|
||||
bonusIcon.gameObject.SetActive(false);
|
||||
bonusTimerText.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b01c170304735a241bc36fff9ab0dd50
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class BonusPickup : MonoBehaviour
|
||||
{
|
||||
public BonusEffect bonusEffect;
|
||||
public float rotationSpeed = 100f;
|
||||
|
||||
private GameObject _originalPrefab;
|
||||
|
||||
public void Init(GameObject prefab)
|
||||
{
|
||||
_originalPrefab = prefab;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
transform.Rotate(Vector3.up, rotationSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
if (BonusManager.Instance != null && bonusEffect != null)
|
||||
{
|
||||
BonusManager.Instance.ActivateBonus(bonusEffect);
|
||||
Debug.Log("бонус подобран");
|
||||
}
|
||||
|
||||
if (_originalPrefab != null)
|
||||
SimpleObjectPool.Instance.ReturnToPool(_originalPrefab, gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b542a0080e584884f8d0bc2ae46aaf59
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 095f133ed0b1459449748ef072132e77
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f045b7417984498aaf503eb5afb7c313
|
||||
timeCreated: 1783938890
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "X2Bonus", menuName = "Bonuses/x2 Bonus")]
|
||||
public class X2Bonus : BonusEffect
|
||||
{
|
||||
public override void Activate(GameObject player)
|
||||
{
|
||||
if (GameManager.Instance != null)
|
||||
{
|
||||
GameManager.Instance.SetScoreMultiplier(2);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deactivate(GameObject player)
|
||||
{
|
||||
if (GameManager.Instance != null)
|
||||
{
|
||||
GameManager.Instance.SetScoreMultiplier(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5dc2ead9299e0bc499c6104712ece1d0
|
||||
Reference in new issue
Block a user