- Home /
Should I use Resource.Load to switch between themes?
Hi,
I'm almost finished with a really simple game and a key feature of this game is the ability to change themes.
I've done this by using cases for each theme but now that I'm reaching ~10 themes it seems like an awful lot of code (reference all the objects and change their sprites for every one of the 10 cases).
What I'm curious is could I have a dynamic string that changes based on the case (mentioned above) and the replace all the sprites (which would be put in an array) with the sprites at the new path? (I guess all sprites should be named the same in their respective folders)
Would this by any chance be possible? Or is there a simpler way of doing this that I'm not aware of?
Thanks!
Answer by Cherno · Apr 18, 2015 at 08:15 PM
Changing the path string and then using Resource.Load would work, wether it's advisable depends on the frequency of the operation. If it can hapen at will/frequently, then quicker option might be better. Perhaps a Dictionary that has the styles as keys and the Materials, GameObject or whatever as Values? Maybe it can even use generic object types as Values for more flexibility.
Thanks Cherno. The Dictionary possibility slipped right through my head. Indeed, the user would be able to switch it at will.
You could also look into reading from an X$$anonymous$$L file so you populate your style classes at game start without having to "hard-code" it, you just have to type it in comofrtably in the X$$anonymous$$L file in a ordered structure.
Your answer
![](https://koobas.hobune.stream/wayback/20220613193442im_/https://answers.unity.com/themes/thub/images/avi.jpg)