Sure! Here is the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Health : MonoBehaviour
{
public float size = 1, health = 50000;
public GameObject Baby;
void Update()
{
//Health loses one every time Update is cycled through
health -= size;
//If they run out of health they die
if (health < 0)
{
Destroy(Baby);
}
}
private void OnTriggerEnter(Collider col)
{
switch (col.tag)
{
case "Frutgtable":
//If they find a piece of food they gain 2500 health
health = health + 2500;
break;
}
}
}
I thought it might have been static too but it turns out that it isn’t. The only other thing I can think of that links all the parents/children is that they all share the same prefab. Is it possible that they are all storing and inheriting their health variable from the original prefab? I don’t think this is the issue because I am pretty sure instantiating a copy of the prefab disconnects it from the original but I am not entirely sure.