I'm trying to get the hunger value from anotherscript etc and it works, but as it is updated in its script, i can't update it in the current script, since the value is only called once I need some help to work around this:
private AIbehaviour AIb;
private int amountOfWorkers;
private List worker = new List();
public struct WorkersInfo //had no better idea lol
{
public float hunger;
public float sanity;
public float tiredness;
public bool workBoost;
public string Name;
}
private WorkersInfo[] wi = new WorkersInfo[50]; //50 just incase
[Multiline]
private string TextObj = "Workers Status's: \n";
void updateText() {
if (worker.Count == 0) {
worker.Clear();
} else { //grab value from 0 index and remove it, until update is called again
TextObj += "\n" + wi[worker[0]].Name + ": \n" //with a new value ^
+ "- Hunger: " + wi[worker[0]].hunger+ "\n" //updated once here
+ "- Sanity: " + wi[worker[0]].sanity + "\n"
+ "- Tiredness: " + wi[worker[0]].tiredness + "\n"
+ "- Workboost Enabled: " + wi[worker[0]].workBoost + "\n";;
worker.RemoveAt(0); //removed from list again to prevent copying
}
}
void getWorkersInfo() {
foreach (Transform child in workerList) {
AIb = child.GetComponent();
if (AIb.available && !AIb.isCountedIn) { //look for every worker
amountOfWorkers += 1;
worker.Add(amountOfWorkers); //add to list
AIb.isCountedIn = true; //become unfindable to stop duplication
wi[amountOfWorkers].hunger = AIb.hunger; //save the value to var
wi[amountOfWorkers].sanity = AIb.sanity;
wi[amountOfWorkers].tiredness = AIb.tiredness;
wi[amountOfWorkers].Name = AIb.Name;
wi[amountOfWorkers].workBoost = AIb.workBoost;
updateText(); //call update for every worker found
}
}
}
//after all workers are found and correctly added, there is no way of updating its properties
any ideas? I also figured that i'd probably have to completely replace the updateText since it will just add new ones, and you can't really update the text's variables only, any ideas people?
↧