Implement enemies getting to a finish, enemy dying
This commit is contained in:
20
Assets/Scripts/Components/DetectTriggerComponent.cs
Normal file
20
Assets/Scripts/Components/DetectTriggerComponent.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class DetectTriggerComponent : MonoBehaviour
|
||||
{
|
||||
public UnityEvent<Collider> onTriggerEnter;
|
||||
public UnityEvent<Collider> onTriggerExit;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
onTriggerEnter?.Invoke(other);
|
||||
}
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
onTriggerExit?.Invoke(other);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Components/DetectTriggerComponent.cs.meta
Normal file
11
Assets/Scripts/Components/DetectTriggerComponent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f91e2b638d21b0a4587037236a3f11d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
Assets/Scripts/Components/EnemyComponent.cs
Normal file
36
Assets/Scripts/Components/EnemyComponent.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class EnemyComponent : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
[Required]
|
||||
[OnValueChanged("Setup")]
|
||||
private Enemy enemy;
|
||||
|
||||
[ReadOnly]
|
||||
[SerializeField]
|
||||
private bool isDead;
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent<int> updateInitialHealth;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Setup();
|
||||
}
|
||||
|
||||
private void Setup()
|
||||
{
|
||||
updateInitialHealth.Invoke(enemy.health);
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
Destroy(gameObject, 3);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Components/EnemyComponent.cs.meta
Normal file
11
Assets/Scripts/Components/EnemyComponent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 974d4ceac4eca1b4cb9a6cc199048116
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,26 +7,15 @@ using UnityEngine.EventSystems;
|
||||
|
||||
public class HealthComponent : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
[Required]
|
||||
[OnValueChanged("Setup")]
|
||||
private Enemy enemy;
|
||||
|
||||
[ReadOnly]
|
||||
[SerializeField]
|
||||
private int health;
|
||||
|
||||
[ReadOnly]
|
||||
[SerializeField]
|
||||
private bool isDead;
|
||||
|
||||
public UnityEvent onDied;
|
||||
|
||||
[Button]
|
||||
public void Setup()
|
||||
public void Setup(int health)
|
||||
{
|
||||
health = enemy.health;
|
||||
isDead = false;
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
public void TakeDamage(int damage)
|
||||
@@ -40,17 +29,10 @@ public class HealthComponent : MonoBehaviour
|
||||
|
||||
if (health == 0)
|
||||
{
|
||||
isDead = true;
|
||||
onDied.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
[Button]
|
||||
private void Take10Damage()
|
||||
{
|
||||
TakeDamage(10);
|
||||
}
|
||||
|
||||
[Button]
|
||||
private void Kill()
|
||||
{
|
||||
|
||||
@@ -61,7 +61,6 @@ public class NavMeshComponent : MonoBehaviour
|
||||
|
||||
private bool ReachedDestinationOrGaveUp()
|
||||
{
|
||||
|
||||
if (agent.pathPending)
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user