using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; using KairoEngine.Core; using KairoEngine.SFX; using KairoEngine.Inventory; namespace KairoEngine.CharacterSystem { public class DamageEmitter : MonoBehaviour { public string title = "Damager"; public int damage = 1; public int armorPiercing = 0; public float attackTime = 0.8f; public CharacterController character; public SFXGroup hitSFXGroup; private CharacterController damagingTarget; private float counter = 0f; void Update() { if(damagingTarget != null) { counter += Time.deltaTime; if(counter > attackTime) { counter = 0f; damagingTarget = null; } } } public void OnTriggerEnter(Collider collider) { if(this.enabled == false) return; //Debug.Log("Damaging " + collider.gameObject.name); Vector3 point = new Vector3(); point = collider.ClosestPoint(transform.position); CharacterController targetCharacter = collider.gameObject.transform.root.GetComponent()?.character; if(targetCharacter != null) { if(targetCharacter == character || targetCharacter == damagingTarget) return; if(damagingTarget == null) damagingTarget = targetCharacter; if(targetCharacter.damageController != null) { targetCharacter.damageController.Damage(this, point); } } if(collider.material != null) hitSFXGroup.Play(collider.material, point); } } }