mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-27 14:30:17 +00:00
46 lines
856 B
C#
46 lines
856 B
C#
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.Events;
|
|||
|
|
|||
|
namespace SanAndreasUnity.Behaviours
|
|||
|
{
|
|||
|
|
|||
|
public class DamageInfo
|
|||
|
{
|
|||
|
public float amount = 0f;
|
|||
|
public object data = null;
|
|||
|
}
|
|||
|
|
|||
|
public class Damageable : MonoBehaviour
|
|||
|
{
|
|||
|
|
|||
|
[SerializeField] private float m_health = 0f;
|
|||
|
public float Health { get { return m_health; } set { m_health = value; } }
|
|||
|
|
|||
|
[SerializeField] private UnityEvent m_onDamage = new UnityEvent ();
|
|||
|
|
|||
|
public DamageInfo LastDamageInfo { get; private set; }
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public void Damage (DamageInfo info)
|
|||
|
{
|
|||
|
this.LastDamageInfo = info;
|
|||
|
m_onDamage.Invoke ();
|
|||
|
}
|
|||
|
|
|||
|
public void HandleDamageByDefault ()
|
|||
|
{
|
|||
|
DamageInfo info = this.LastDamageInfo;
|
|||
|
|
|||
|
this.Health -= info.amount;
|
|||
|
|
|||
|
if (this.Health <= 0f) {
|
|||
|
Destroy (this.gameObject);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|