mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-24 09:08:23 -05:00
43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Assertions;
|
|
using UnityAtoms.BaseAtoms;
|
|
using UnityAtoms.Tags;
|
|
|
|
namespace UnityAtoms.Examples
|
|
{
|
|
public class DecreaseHealth : MonoBehaviour
|
|
{
|
|
public List<StringConstant> TagsAffected { get => _tags; }
|
|
|
|
[SerializeField]
|
|
private IntReference _decreaseBy;
|
|
|
|
[SerializeField]
|
|
private List<StringConstant> _tags;
|
|
|
|
[SerializeField]
|
|
private VoidBaseEventReference _didCollide;
|
|
|
|
void Start()
|
|
{
|
|
Assert.IsNotNull(_decreaseBy);
|
|
Assert.IsNotNull(_tags);
|
|
}
|
|
|
|
public void Do(Collider2D collider)
|
|
{
|
|
if (collider == null) return;
|
|
|
|
if (collider.gameObject.HasAnyTag(_tags))
|
|
{
|
|
collider.GetComponent<UnitHealth>().Health -= _decreaseBy;
|
|
}
|
|
|
|
if (_didCollide != null && _didCollide.Event != null)
|
|
{
|
|
_didCollide.Event.Raise();
|
|
}
|
|
}
|
|
}
|
|
} |