Add damage system and processing system to enemy
This commit is contained in:
34
Assets/Scripts/Components/DetectHitComponent.cs
Normal file
34
Assets/Scripts/Components/DetectHitComponent.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class DetectHitComponent : MonoBehaviour
|
||||
{
|
||||
private static float[] hitMultipliers = new float[] {
|
||||
0.5f,
|
||||
0.75f,
|
||||
1,
|
||||
1.25f,
|
||||
1.5f,
|
||||
2
|
||||
};
|
||||
|
||||
[SerializeField]
|
||||
[ValueDropdown("hitMultipliers")]
|
||||
private float hitMultiplier;
|
||||
|
||||
public OnHitEvent onHit;
|
||||
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
var gameObject = collision.gameObject;
|
||||
var damageDealer = gameObject.GetComponent<DamageDealerComponent>();
|
||||
|
||||
if (damageDealer == null) return;
|
||||
|
||||
onHit.Invoke(new(damageDealer.damage, hitMultiplier, gameObject));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user