re-added a primitive way to kill enemies

This commit is contained in:
BOTAlex 2024-03-27 17:38:09 +01:00
parent 2934646bcb
commit 93c0fa124f
3 changed files with 41 additions and 2 deletions

View File

@ -18,6 +18,7 @@ GameObject:
- component: {fileID: 5669020798899338457} - component: {fileID: 5669020798899338457}
- component: {fileID: 7025838755278696983} - component: {fileID: 7025838755278696983}
- component: {fileID: 3458620527668384477} - component: {fileID: 3458620527668384477}
- component: {fileID: -4503587680586986928}
m_Layer: 0 m_Layer: 0
m_Name: EnemyBase m_Name: EnemyBase
m_TagString: Enemy m_TagString: Enemy
@ -185,7 +186,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
GlobalObjectIdHash: 3891322656 GlobalObjectIdHash: 1810720538
InScenePlacedSourceGlobalObjectIdHash: 0 InScenePlacedSourceGlobalObjectIdHash: 0
AlwaysReplicateAsRoot: 0 AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1 SynchronizeTransform: 1
@ -253,4 +254,16 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e071dd818c5a905209e31c2d66ea6390, type: 3} m_Script: {fileID: 11500000, guid: e071dd818c5a905209e31c2d66ea6390, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: 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:

View File

@ -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<HealthComponent>();
health.OnHealthZero.AddListener(OnDeath);
}
private void OnDisable()
{
health.OnHealthZero.RemoveListener(OnDeath);
}
private void OnDeath()
{
Destroy(gameObject);
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0c03d2ee433025242bc14fc1bae3a9ab