- Home /
This question was
closed Dec 16, 2018 at 01:04 PM by
hexagonius for the following reason:
3rd question about the same topic
Question by
Supermacka · Dec 16, 2018 at 12:43 PM ·
updateforloop
How to count tagged objects while scene is updating?
Hi,
I am trying to create for-loops that count the number of objects in my scene with the tags ("ColorFloorRed") and ("ColorFloorBlue"). For some reason the loops only count the tagged objects before the amount of them change. So if the amount of ("ColorFloorRed") objects change while playing nothing happens.
How can I count the number of objects with the tag ("ColorFloorRed") and ("ColorFloorBlue") and update the number if the amount changes while the scene is running?
Thanks in advance.
public class ColorCount : MonoBehaviour
{
public float totalFloorTiles;
public float redCount;
public float blueCount;
GameObject[] colorFloor;
GameObject[] colorFloorRed;
GameObject[] colorFloorBlue;
// Use this for initialization
void Start ()
{
colorFloor = GameObject.FindGameObjectsWithTag("ColorFloor");
colorFloorRed = GameObject.FindGameObjectsWithTag("ColorFloorRed");
colorFloorBlue = GameObject.FindGameObjectsWithTag("ColorFloorBlue");
}
// Update is called once per frame
void Update ()
{
for (int i = 0; i <= colorFloor.Length; i++)
{
totalFloorTiles = i;
}
for (float r = 0; r < colorFloorRed.Length; r++)
{
redCount = r;
}
for (float b = 0; b <= colorFloorBlue.Length; b++)
{
blueCount = b;
}
Comment