I approached mine a little bit differently. It’s called Village Defender instead of Glitch Garden and features Zombies as the attackers.
I created a Base prefab and positioned it to be around the backdrop part that represents the base (far left of the screen). I attached the Health script to it, attached a RigidBody2D to it and gave it some health in the inspector. Also marked it as a kinematic rigidbody and that’s all that was needed so that the existing code and Zombies could attack the base.
Then i created a base script (empty dummy script) and attached it to the Base prefab. Then in the HealthDisplay script that I attached to the base I have
tusing System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HealthDisplay : MonoBehaviour
{
private Text healthText;
private Base playerBase;
private Health health;
// Start is called before the first frame update
void Start()
{
healthText = GetComponent<Text>();
playerBase = FindObjectOfType<Base>();
health = playerBase.GetComponent<Health>();
UpdateDisplay();
}
private void Update()
{
UpdateDisplay();
}
private void UpdateDisplay()
{
healthText.text = health.GetHealth().ToString();
}
}
Here’s a video to showcase this - https://youtu.be/YB_hQEYo-B8.