Coding For Color
#PanicRoom Day 065
#100DaysOfCode R2D31
#100DaysOfGameDev R2D30
Who would have thought taking white label assets and changing the color via code would be difficult? Not me, but it definitely took me more than several minutes and a whole lot of trial and error. I did finally figure out how to get it and now I have the ability to set my grid overlay to any color I wish.
The trick was solving how to access the SpriteRenderer for each of my grid label parts, as my grid system is very dynamic and doesn’t have a set number of pieces each time. It would have been easy to set up a GetComponent call for each label on a finite set up, but my labels are generated by three individual digit components (0 through 9 for each of the hundreds, tens, and ones digits – literally a thousand combinations) and it is completely random how many grid labels will be needed for each axis of the grid.
The key was calling each objects SpriteRenderer and setting the color as soon as it is generated, that way no matter how many times the Function is called it will generate a properly colored label. It was just a lot of moving parts to wrap my head around, but I’m glad I figured it out. I want my code to be adaptable and modifiable as I move forward, that way as I have changes or additions I want to make it will be easier to implement. Always plan ahead for the unforeseen! I may not know what I want to add or change in the future, but I can at least make it as easy on myself as possible when that time comes.