First, I search through the game symbols that I am interested in (let’s call them wild clones) and then I search through their children (to locate the game object that has the animation) and then I activate those animations.
private IEnumerator EnableWilds(float delayBetweenWildsAppear)
{
WildSymbol[] wilds = FindObjectsOfType<WildSymbol>();
GameObject[] symbols = new GameObject[wilds.Length];
for (int i = 0; i < wilds.Length; i++)
{
symbols[i] = wilds[i].gameObject;
}
for (int i = 0; i < symbols.Length; i++)
{
if ( symbols[i].name.Contains("(Clone)") )
{
int reelIndex = symbols[i].GetComponentInParent<GameReel>().ReelIndex;
int indexOnReel = symbols[i].GetComponent<WildSymbol>().IndexOnReel;
// ??
for (int j = 0; j < symbols[i].transform.childCount; j++)
{
if ( symbols[i].transform.GetChild(j).gameObject.name.Contains("MM_wild") )
{
symbols[i].transform.GetChild(j).gameObject.SetActive(true);
yield return new WaitForSeconds(delayBetweenWildsAppear);
}
}
}
}
}
I started thinking about how I can activate those wilds starting from the top left corner, and coming down the reel and moving on to the next reel and animating the wilds from top to bottom, etc…
So, I realized I need to get each symbol’s reel index (i.e. column number) and index on reel (i.e. position on the reel) so I go Reel1 and then wild clone 1 and 2 and 3, and then Reel2 followed by wild clone 1 and 2 and 3, and so on…
I am trying to do this where I have put a // ?? but at this point, I am a bit lost, conceptually. I cannot figure out how to perform tghis traversal.
First take a look at any one of 4.9 MILLION tutorial videos out there.
This is extremely well-travelled ground, lots of engineering and study has been devoted to it, and you need to get familiar with what the state of the art is now before anyone can type meaningfully at you.
2D arrays could be helpful for you here. Also I’m not sure about searching with “(Clone)”…depending on how you create/set the tiles, maybe you can instead have references to them permanently via the Inspector in arrays. Or if you do instantiate them, give them names right after instantiation using the iterator int at the end of the name. This would allow the names to actually be “Reel1_Index1” etc. You can also give each one a unique index that counts up, so it would go from 0-14 (or 1-15), and you can determine position with modulus and division.
You’re doing more work than you need too that’s for sure.
You get an array of WildSymbols, then you iterate over the array of WildSymbols to get all the GameObjects and put those into another array. All you need to do is use the first array, the second one is redundant.
You then iterate over the second unnecessary array looking to see if it contains “Clone” not sure what that is for, i am thinking you instantiated them at runtime. If it does contain “Clone” you then get the parent component GameReel and WildSymbol which the first array already had for you. WildSymbol should have a reference to its GameReel, so its a bunch of unnecessary work when you could have used the first array the system gave you of WildSymbols, eliminating the expensive GetComponent calls and unnecessary loops, not to mention all the garbage you’re leaving in the memory for the GC to cleanup.
Think OOP, WildSymbol should be able to activate the animations, you shouldn’t need to loop through to find a child object WildSymbol should already have a reference to.
You should have an array of GameReels already referenced and it should have a reference to all the Wilds in order. You would then iterate over the GameReels and tell each one to activate the Wilds in order from the already referenced array of Wilds and the Wilds would then activate the animations.