You've already forked zumbi-game
refactor: encapsulate health check in IsDead method
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[RequireComponent(typeof(Animator))]
|
[RequireComponent(typeof(Animator))]
|
||||||
@@ -27,6 +28,8 @@ public class ZombieController : MonoBehaviour
|
|||||||
private Transform player;
|
private Transform player;
|
||||||
private Animator animator;
|
private Animator animator;
|
||||||
|
|
||||||
|
private bool IsDead() => currentHealth == 0;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
currentHealth = maxHealth;
|
currentHealth = maxHealth;
|
||||||
@@ -36,7 +39,7 @@ public class ZombieController : MonoBehaviour
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (currentHealth == 0) return;
|
if (IsDead()) return;
|
||||||
|
|
||||||
float distance = Vector3.Distance(transform.position, player.position);
|
float distance = Vector3.Distance(transform.position, player.position);
|
||||||
|
|
||||||
@@ -88,6 +91,8 @@ public class ZombieController : MonoBehaviour
|
|||||||
|
|
||||||
public void TakeDamage(float amount)
|
public void TakeDamage(float amount)
|
||||||
{
|
{
|
||||||
|
if (IsDead()) return;
|
||||||
|
|
||||||
currentHealth -= amount;
|
currentHealth -= amount;
|
||||||
Debug.Log($"{gameObject.name} took {amount} damage. HP: {currentHealth}/{maxHealth}");
|
Debug.Log($"{gameObject.name} took {amount} damage. HP: {currentHealth}/{maxHealth}");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user