mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-02-17 05:18:27 +00:00
implement basic vehicle damage logic
This commit is contained in:
parent
29b7ae65f0
commit
faf96838b9
3 changed files with 95 additions and 0 deletions
83
Assets/Scripts/Behaviours/Vehicles/Vehicle_Damage.cs
Normal file
83
Assets/Scripts/Behaviours/Vehicles/Vehicle_Damage.cs
Normal file
|
@ -0,0 +1,83 @@
|
|||
using SanAndreasUnity.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SanAndreasUnity.Behaviours.Vehicles
|
||||
{
|
||||
|
||||
public partial class Vehicle
|
||||
{
|
||||
|
||||
public Damageable Damageable { get; private set; }
|
||||
|
||||
public float Health { get => this.Damageable.Health; set => this.Damageable.Health = value; }
|
||||
|
||||
public float MaxHealth { get; set; } = 1000;
|
||||
|
||||
public bool IsUnderFlame { get; private set; } = false;
|
||||
public bool IsUnderSmoke { get; private set; } = false;
|
||||
|
||||
public float TimeWhenBecameUnderFlame { get; private set; } = float.NegativeInfinity;
|
||||
|
||||
|
||||
|
||||
void Awake_Damage()
|
||||
{
|
||||
this.Damageable = this.GetComponentOrThrow<Damageable>();
|
||||
this.Damageable.OnDamageEvent.AddListener(() => this.OnDamaged());
|
||||
}
|
||||
|
||||
void OnDamaged()
|
||||
{
|
||||
var damageInfo = this.Damageable.LastDamageInfo;
|
||||
|
||||
if (this.Health <= 0)
|
||||
return;
|
||||
|
||||
this.Health -= damageInfo.amount;
|
||||
|
||||
if (this.Health <= 0)
|
||||
{
|
||||
this.Explode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Update_Damage()
|
||||
{
|
||||
|
||||
bool shouldBeUnderSmoke = this.MaxHealth * 0.33f >= this.Health;
|
||||
if (shouldBeUnderSmoke != this.IsUnderSmoke)
|
||||
{
|
||||
// smoke status changed
|
||||
this.IsUnderSmoke = shouldBeUnderSmoke;
|
||||
// update vfx
|
||||
|
||||
}
|
||||
|
||||
bool shouldBeUnderFlame = this.MaxHealth * 0.1f >= this.Health;
|
||||
if (shouldBeUnderFlame != this.IsUnderFlame)
|
||||
{
|
||||
// flame status changed
|
||||
this.IsUnderFlame = shouldBeUnderFlame;
|
||||
if (this.IsUnderFlame)
|
||||
this.TimeWhenBecameUnderFlame = Time.time;
|
||||
// update vfx
|
||||
|
||||
}
|
||||
|
||||
if (this.IsUnderFlame && Time.time - this.TimeWhenBecameUnderFlame >= 5)
|
||||
{
|
||||
// enough time passed since vehicle flamed - explode it
|
||||
this.Explode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Explode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Behaviours/Vehicles/Vehicle_Damage.cs.meta
Normal file
11
Assets/Scripts/Behaviours/Vehicles/Vehicle_Damage.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9cd0352997c20c34f910b45d1f53fe32
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -20,6 +20,7 @@ namespace SanAndreasUnity.Utilities
|
|||
public float Health { get { return m_health; } set { m_health = value; } }
|
||||
|
||||
[SerializeField] private UnityEvent m_onDamage = new UnityEvent ();
|
||||
public UnityEvent OnDamageEvent => m_onDamage;
|
||||
|
||||
public DamageInfo LastDamageInfo { get; private set; }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue