How do i check if same but many objects have x value at maximum?
like i have 5 cubes with a health script and how do i check if all of them have health 100 and if they have 100 then i could just say x bool is true but i dont know how to check if all of them have a value of 100.
Some other gameobject needs to know all 5 of them (public array of health scripts for the inspector to assign all of them to). You can then run a loop and check on each Health script for 100. If it's note return false immediately. Return true after the loop has finished. Since the loop will not break for all 100s, the true return can be reached.
Answer by UnityCoach · Apr 02, 2017 at 07:28 PM
You can have an bool accessor, like :
public bool allFull
{
get { return (a.health == 100 && b.health == 100 && c.health == 100 && d.health == 100 && e.health == 100 ); }
}
but if you consider using it often, like in an Update call, then do it the other way around, have a static bool value, with a set accessor for all heath, that changes this to false, whenever one is less than 100.
Your answer
Follow this Question
Related Questions
Need help with Mute Button 1 Answer
Can I run C# scripts from Unity on an Ubuntu 19.10 macine? Huge stack of compiling errors. 0 Answers
How to obtain a variable in update that doesn't behave like a loop? C# 1 Answer
How do i have game object in the middle of a Catmull spline? 0 Answers
Unity/C# Respawn and score Problem 1 Answer