Hello, I have this code snippet that is used everywhere in my code and I would like to optimize it better as it is used always during time critical parts.
Transform tempStatusGroup;
tempStatusGroup = targetHpBar.transform.GetChild(0);
bool checkIfAdd = true;
int totalStatusEffects = 0;
//Now looping through each buff / debuff!! Which is contained in the monsters HP bar as a child of status group!
foreach(Transform child in tempStatusGroup){
//Ignore DoT Effects and HoT Effects!
if (child.name.Contains(status) && !child.name.Contains("dot") && !child.name.Contains("hot")){
string childText = child.GetComponentInChildren<Text>().text;
int childTextInt = IntParseFast(childText);
if (childTextInt < turnsOfStatus){
child.GetComponentInChildren<Text>().text = turnsOfStatus.ToString();
}
checkIfAdd = false;
}
//Count the total amount of status effects and make sure it is not above 10!
totalStatusEffects++;
if (totalStatusEffects >= 10){
//Too many status effects on monster! DON'T ADD MORE!
checkIfAdd = false;
Pretty much I have a monster with some gameobjects (with only a text component) to display their buffs/debuffs, and I need to check them to look for certain one’s quickly and efficiently. They also have a text component with a number and I always negative that number by one to count down, and its a lot of steps to make it work and I don’t like that.
Whenever I check for something like Damage over time debuff, I have to search through the children to see if the name matches the string and I know this is not the best way to do it so any help on that would be greatly appreciated.
Thanks for any advice!