- Home /
How to detect that array items are triggered?
HI,
I have created an array of sprites which will change color on trigger. Now I am working where I have to read/detect that all spites of the array are triggered and changed. So another sprite animation/color change function can be played. Unable to understand that how to detect/know that all sprites are triggered? Can anyone please suggest me what method i can use here ?
using UnityEngine;
using System.Collections;
public class BG_Sprite_List : MonoBehaviour { public GameObject [] backgrounds;
public backgrounds<GameObject> background ;
void ColorFillEffect()
{
SpriteRenderer = GetComponent<SpriteRenderer> ();
start = new Color (start.r, start.g, start.b, 0.0f);
end = SpriteRenderer.color;
}
void Update ()
{
for (int i = 0; i < background.Count; i++)
{
//another sprite animation/color change function can be played
ColorFillEffect();
}
}
}
Answer by $$anonymous$$ · Sep 21, 2014 at 03:52 PM
You can declare new Bool variable to hold whether sprite has been Triggered or not and set it to true in OnTriggerEnter2D(Collider2D), then run loop:
for (int i = 0; i < Sprites.Count or Length; i++)
{
if (!Sprites[i].IsTriggered)
{
// Sprite is not triggered --> BREAK or RETURN
break;
}
}
Hi Riviere Delta, sorry for late response, I dont quite understand your Class Logic here becouse I see it like this: Code you pasted is for some kind of 'Cell $$anonymous$$anager' becouse it contains Array with Cells. But why this class also declare 'IsTrigger' bool Variable if every cell has to have this variable, not only this alone class :). That makes no sense. If it is like that, try to look up into your Cell Class definition (for each individual Cell) and declare IsTrigger there so every Cell has that boolean and then you can do something like this:
if (!cells[i].GetComponent<CellEntity>().IsTriggered)
to detect if every individual Cell in the scene has been triggered or not. Hope this is it :)
Your answer
