unity-atoms/Examples/Assets/InfinityWaves/Projectile/DecreaseHealth.cs

43 lines
942 B
C#
Raw Normal View History

2020-03-04 18:48:39 -05:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;
using UnityAtoms.BaseAtoms;
using UnityAtoms;
using UnityAtoms.Tags;
public class DecreaseHealth : MonoBehaviour
{
2020-03-11 16:11:27 -04:00
public List<StringConstant> TagsAffected { get => _tags; }
2020-03-04 18:48:39 -05:00
[SerializeField]
private IntReference _decreaseBy;
[SerializeField]
private List<StringConstant> _tags;
[SerializeField]
2020-03-08 07:32:41 -04:00
private VoidBaseEventReference _didCollide;
2020-03-04 18:48:39 -05:00
void Start()
{
Assert.IsNotNull(_decreaseBy);
Assert.IsNotNull(_tags);
}
public void Do(Collider2D collider)
{
2020-03-15 19:18:26 -04:00
if (collider == null) return;
2020-03-04 18:48:39 -05:00
if (collider.gameObject.HasAnyTag(_tags))
{
collider.GetComponent<UnitHealth>().Health -= _decreaseBy;
}
2020-03-08 07:32:41 -04:00
if (_didCollide != null && _didCollide.Event != null)
{
_didCollide.Event.Raise();
}
2020-03-04 18:48:39 -05:00
}
}