33 lines
685 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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();
}
}