diff --git a/Assets/Scripts/Behaviours/Ped/Ped.cs b/Assets/Scripts/Behaviours/Ped/Ped.cs index 8bfb52a6..53e26fac 100644 --- a/Assets/Scripts/Behaviours/Ped/Ped.cs +++ b/Assets/Scripts/Behaviours/Ped/Ped.cs @@ -207,11 +207,6 @@ namespace SanAndreasUnity.Behaviours void OnDisable () { s_allPeds.Remove (this); - - if (this.PlayerModel != null) - { - this.PlayerModel.DetachRagdoll(this.KillingDamageInfo); - } } diff --git a/Assets/Scripts/Behaviours/Ped/Ped_Damage.cs b/Assets/Scripts/Behaviours/Ped/Ped_Damage.cs index b5821699..cc2a139d 100644 --- a/Assets/Scripts/Behaviours/Ped/Ped_Damage.cs +++ b/Assets/Scripts/Behaviours/Ped/Ped_Damage.cs @@ -21,6 +21,8 @@ namespace SanAndreasUnity.Behaviours /// public DamageInfo KillingDamageInfo { get; set; } + private bool m_alreadyKilled = false; + void AwakeForDamage () @@ -130,6 +132,26 @@ namespace SanAndreasUnity.Behaviours msg.Text = damageAmount.ToString(); } + public void Kill() + { + F.RunExceptionSafe(this.KillInternal); + } + + void KillInternal() + { + if (m_alreadyKilled) + return; + + m_alreadyKilled = true; + + if (this.PlayerModel != null) + { + this.PlayerModel.DetachRagdoll(this.KillingDamageInfo); + } + + Object.Destroy(this.gameObject); + } + } } diff --git a/Assets/Scripts/Behaviours/Ped/States/BaseScriptState.cs b/Assets/Scripts/Behaviours/Ped/States/BaseScriptState.cs index 80ad046e..e904a19e 100644 --- a/Assets/Scripts/Behaviours/Ped/States/BaseScriptState.cs +++ b/Assets/Scripts/Behaviours/Ped/States/BaseScriptState.cs @@ -319,7 +319,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States if (m_ped.Health <= 0) { m_ped.KillingDamageInfo = damageInfo; - Object.Destroy(m_ped.gameObject); + m_ped.Kill(); } // notify clients diff --git a/Assets/Scripts/UI/PedsWindow.cs b/Assets/Scripts/UI/PedsWindow.cs index 2344f817..e2ebf661 100644 --- a/Assets/Scripts/UI/PedsWindow.cs +++ b/Assets/Scripts/UI/PedsWindow.cs @@ -164,7 +164,7 @@ namespace SanAndreasUnity.UI { { foreach (var p in Ped.AllPeds) { - Destroy (p.gameObject); + p.Kill(); } }