Moved from swarm to NavMesh - need to fix the enemy navigation! Review the animation controller to see if anything is being triggered.
This commit is contained in:
68
Assets/Scripts/Fortification.cs
Normal file
68
Assets/Scripts/Fortification.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class Fortification : MonoBehaviour
|
||||
{
|
||||
// Global list so Siege enemies can easily find targets
|
||||
public static List<Fortification> AllFortifications = new List<Fortification>();
|
||||
|
||||
[Header("Health Settings")]
|
||||
public float maxHealth = 500f;
|
||||
public float currentHealth;
|
||||
|
||||
[Header("Visual Stages (Assign GameObjects)")]
|
||||
public GameObject fullyBuiltModel;
|
||||
public GameObject damagedModel;
|
||||
public GameObject ruinedModel;
|
||||
|
||||
private Collider barrierCollider;
|
||||
public bool IsDestroyed => currentHealth <= 0;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
barrierCollider = GetComponent<Collider>();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
AllFortifications.Add(this);
|
||||
currentHealth = maxHealth;
|
||||
UpdateVisuals();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
AllFortifications.Remove(this);
|
||||
}
|
||||
|
||||
public void TakeDamage(float amount)
|
||||
{
|
||||
if (IsDestroyed) return;
|
||||
|
||||
currentHealth -= amount;
|
||||
UpdateVisuals();
|
||||
}
|
||||
|
||||
public void Repair(float amount)
|
||||
{
|
||||
if (currentHealth >= maxHealth) return;
|
||||
|
||||
currentHealth += amount;
|
||||
currentHealth = Mathf.Min(currentHealth, maxHealth); // Cap at max
|
||||
UpdateVisuals();
|
||||
}
|
||||
|
||||
private void UpdateVisuals()
|
||||
{
|
||||
// Swap models based on health thresholds
|
||||
fullyBuiltModel.SetActive(currentHealth > maxHealth * 0.5f);
|
||||
damagedModel.SetActive(currentHealth > 0 && currentHealth <= maxHealth * 0.5f);
|
||||
ruinedModel.SetActive(IsDestroyed);
|
||||
|
||||
// When destroyed, turn the collider into a trigger so the horde can pour through the rubble
|
||||
if (barrierCollider != null)
|
||||
{
|
||||
barrierCollider.isTrigger = IsDestroyed;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user