From 93c0fa124f21ce0a3a7d0040150ebaadfffe87dd Mon Sep 17 00:00:00 2001 From: BOTAlex Date: Wed, 27 Mar 2024 17:38:09 +0100 Subject: [PATCH] re-added a primitive way to kill enemies --- .../Networked/Enemies/EnemyBase.prefab | 17 +++++++++++-- .../Scripts/HeathSystem/DestroyOnNoHealth.cs | 24 +++++++++++++++++++ .../HeathSystem/DestroyOnNoHealth.cs.meta | 2 ++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 Assets/Scripts/HeathSystem/DestroyOnNoHealth.cs create mode 100644 Assets/Scripts/HeathSystem/DestroyOnNoHealth.cs.meta diff --git a/Assets/Prefabs/Networked/Enemies/EnemyBase.prefab b/Assets/Prefabs/Networked/Enemies/EnemyBase.prefab index 7ae1448..07da718 100644 --- a/Assets/Prefabs/Networked/Enemies/EnemyBase.prefab +++ b/Assets/Prefabs/Networked/Enemies/EnemyBase.prefab @@ -18,6 +18,7 @@ GameObject: - component: {fileID: 5669020798899338457} - component: {fileID: 7025838755278696983} - component: {fileID: 3458620527668384477} + - component: {fileID: -4503587680586986928} m_Layer: 0 m_Name: EnemyBase m_TagString: Enemy @@ -185,7 +186,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} m_Name: m_EditorClassIdentifier: - GlobalObjectIdHash: 3891322656 + GlobalObjectIdHash: 1810720538 InScenePlacedSourceGlobalObjectIdHash: 0 AlwaysReplicateAsRoot: 0 SynchronizeTransform: 1 @@ -253,4 +254,16 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e071dd818c5a905209e31c2d66ea6390, type: 3} m_Name: m_EditorClassIdentifier: - spawnedId: -1 + InitialID: -1 +--- !u!114 &-4503587680586986928 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7065654593080984807} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0c03d2ee433025242bc14fc1bae3a9ab, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Scripts/HeathSystem/DestroyOnNoHealth.cs b/Assets/Scripts/HeathSystem/DestroyOnNoHealth.cs new file mode 100644 index 0000000..52eed05 --- /dev/null +++ b/Assets/Scripts/HeathSystem/DestroyOnNoHealth.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(HealthComponent))] +public class DestroyOnNoHealth : MonoBehaviour +{ + HealthComponent health; + private void OnEnable() + { + health = GetComponent(); + health.OnHealthZero.AddListener(OnDeath); + } + + private void OnDisable() + { + health.OnHealthZero.RemoveListener(OnDeath); + } + + private void OnDeath() + { + Destroy(gameObject); + } +} diff --git a/Assets/Scripts/HeathSystem/DestroyOnNoHealth.cs.meta b/Assets/Scripts/HeathSystem/DestroyOnNoHealth.cs.meta new file mode 100644 index 0000000..325f114 --- /dev/null +++ b/Assets/Scripts/HeathSystem/DestroyOnNoHealth.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 0c03d2ee433025242bc14fc1bae3a9ab \ No newline at end of file