33 lines
685 B
C#
33 lines
685 B
C#
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
|
||
[RequireComponent (typeof(Collider))]
|
||
public class Damager : MonoBehaviour
|
||
{
|
||
[SerializeField] private int Damage;
|
||
private GameObject Owner;
|
||
|
||
public UnityEvent OnCollision;
|
||
|
||
public void Initialize(GameObject Owner)
|
||
{
|
||
if (OnCollision == null) OnCollision = new();
|
||
|
||
this.Owner = Owner;
|
||
}
|
||
|
||
|
||
private void OnTriggerEnter(Collider other)
|
||
{
|
||
if(other.TryGetComponent<Hitbox>(out var hitbox))
|
||
{
|
||
//Коллизия с собой
|
||
if (hitbox.Owner == this.Owner) return;
|
||
|
||
hitbox.TakeDamage(Damage);
|
||
}
|
||
|
||
OnCollision?.Invoke();
|
||
}
|
||
}
|