I have made a simple script which should track how many entities are entering a building and how many entities are leaving the building. For some reason, the count of staffAtWork never changes, but the functions are being called.
public ServeFood serveFood;
void Start()
{
serveFood = transform.parent.parent.GetComponent<ServeFood>();
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.GetComponent<CivilianInfo>().work == this.gameObject)
{
serveFood.staffAtWork = serveFood.staffAtWork + 1;
Debug.Log(other.gameObject.GetComponent<CivilianInfo>().forename + " is working at " + transform.parent.parent.gameObject.name);
}
}
void OnTriggerExit(Collider other)
{
if(other.gameObject.GetComponent<CivilianInfo>().work == this.gameObject)
{
serveFood.staffAtWork = serveFood.staffAtWork - 1;
Debug.Log(other.gameObject.GetComponent<CivilianInfo>().forename + " is no longer working at " + transform.parent.parent.gameObject.name);
}
}
}
The script (ServeFood) it is looking to -
public class ServeFood : MonoBehaviour {
public int surplusFoodValue;
public bool isWorked; //Unworked service buildings do not distribute food
public int staffAtWork; //Is someone currently working in the building?
public float timer = 0;
public float timerMax = 0.1f;
EmployeeInfo employInfo;
OccupationController occupationControl;
void Start()
{
employInfo = GetComponent<EmployeeInfo>();
occupationControl = GameObject.Find("OccupationControl").GetComponent<OccupationController>();
}
void Update()
{
if(employInfo.myWorkers.Count < employInfo.capacity)
{
if(isWorked == false && occupationControl.unemployedVillagers.Count > 0)
{
occupationControl.getJob(employInfo);
}
}
else
{
occupationControl.removeFromList(gameObject);
isWorked = true;
}
}
}
The first script does find the correct ServeFood component. It is Public, so I am able to check that within gameplay.
Any idea why staffAtWork isn’t changing from 0?
Thanks in advance.