33 lines
792 B
C#
33 lines
792 B
C#
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
|
||
[RequireComponent(typeof(Collider), typeof(Rigidbody))]
|
||
public class Damager : MonoBehaviour
|
||
{
|
||
[SerializeField] private int Damage;
|
||
[SerializeField] private GameObject ImpactEffect;
|
||
private GameObject Owner;
|
||
|
||
public void Initialize(GameObject Owner)
|
||
{
|
||
this.Owner = Owner;
|
||
}
|
||
|
||
|
||
private void OnTriggerEnter(Collider other)
|
||
{
|
||
if (other.TryGetComponent<Hitbox>(out var hitbox))
|
||
{
|
||
//Коллизия с собой
|
||
if (hitbox.Owner == this.Owner) return;
|
||
|
||
hitbox.TakeDamage(Damage);
|
||
}
|
||
|
||
if(ImpactEffect != null)
|
||
Instantiate(ImpactEffect, transform.position, Quaternion.identity);
|
||
|
||
Destroy(gameObject);
|
||
}
|
||
}
|