-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKillHealZone.cs
59 lines (48 loc) · 1.72 KB
/
KillHealZone.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
using System.Collections.Generic;
using UnityEngine;
namespace PlanetTaxi
{
[RequireComponent(typeof(Collider))]
public class KillHealZone : MonoBehaviour
{
[Tooltip("Mennyit növelje/csökkentse a benne tartózkodó objektumok életét másodpercenként a trigger")]
[SerializeField] private float _hpChange = 10.0f;
[Tooltip("Objektum ami bekapcsol, ha van valami a triggerben")]
[SerializeField] private GameObject _workingIndicator;
[Tooltip("Objektum ami bekapcsol, ha van nincsen semmi a triggerben")]
[SerializeField] private GameObject _notWorkingIndicator;
private List<IDamageable> _currentlyInTrigger = new List<IDamageable>();
private void Start()
{
if (_workingIndicator != null) _workingIndicator.SetActive(false);
if (_notWorkingIndicator != null) _notWorkingIndicator.SetActive(true);
}
private void Update ()
{
if (_currentlyInTrigger.Count > 0) for (int i = 0; i < _currentlyInTrigger.Count; i++) _currentlyInTrigger[i].ChangeHP(_hpChange * Time.deltaTime);
}
private void OnTriggerEnter(Collider other)
{
IDamageable tmp = other.GetComponent<IDamageable>();
if (tmp != null)
{
_currentlyInTrigger.Add(tmp);
if (_workingIndicator != null) _workingIndicator.SetActive(true);
if (_notWorkingIndicator != null) _notWorkingIndicator.SetActive(false);
}
}
private void OnTriggerExit(Collider other)
{
IDamageable tmp = other.GetComponent<IDamageable>();
if (tmp != null)
{
_currentlyInTrigger.Remove(tmp);
if (_currentlyInTrigger.Count < 1)
{
if (_workingIndicator != null) _workingIndicator.SetActive(false);
if (_notWorkingIndicator != null) _notWorkingIndicator.SetActive(true);
}
}
}
}
}