-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBonusItem.cs
60 lines (52 loc) · 1.57 KB
/
BonusItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using UnityEngine;
using System;
public class BonusItem
{
// Типы бонусов
public enum BonusType
{
Speed,
Score,
Health
}
// Свойства бонуса
public BonusType Type { get; private set; }
public int Value { get; private set; }
public float Duration { get; private set; } // Длительность эффекта (в секундах)
private bool isActive; // Флаг активности бонуса
// События
public static event Action<BonusType, int, float> OnBonusActivated;
public static event Action<BonusType> OnBonusCancelled;
// Конструктор
public BonusItem(BonusType type, int value, float duration)
{
Type = type;
Value = value;
Duration = duration;
isActive = false;
}
// Метод для активации бонуса
public void Activate()
{
if (isActive)
{
Debug.LogWarning("Bonus is already active!");
return;
}
isActive = true;
Debug.Log($"Bonus of type {Type} activated with value {Value} for {Duration} seconds.");
OnBonusActivated?.Invoke(Type, Value, Duration);
}
// Метод для отмены бонуса
public void Cancel()
{
if (!isActive)
{
Debug.LogWarning("Bonus is not active and cannot be cancelled!");
return;
}
isActive = false;
Debug.Log($"Bonus of type {Type} has been cancelled.");
OnBonusCancelled?.Invoke(Type);
}
}