Skill Tree Activated

The quest to become an indie game developer

#100DaysOfCode#100DaysOfGameDevC#Illogical BaconPanic RoomScript-writingUnityVisual Studio

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.

setting the different grid labels to their respective colors using RGB values

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.

using SpriteRenderer.color to make the grid labels their respective color

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.

Leave a Reply

Your email address will not be published. Required fields are marked *