- Home /
How to go about making multiple color themes for a simple game?
I have a simple geometry kind of game. It uses basic colors on gameobjects. I want to have multiple color themes.
Should I have 6-7 of the same materials for each theme? Or should I have just one material for each prefab and store different color values in code which I can apply to the materials based on the theme picked?
Or, is there a better way to do this?
Thanks.
Answer by K-Anator · May 06, 2019 at 10:15 PM
I believe, depending on how you're currently colouring your objects, that you can change the albedo via code. https://docs.unity3d.com/ScriptReference/Material.SetColor.html
What kind of code have you currently got that's responsible for setting the objects colour? How many colours are you looking to change?
There are 12 colors per theme, and I want about 10 themes.
As of right now, I just dragged a material onto each prefab. But since I want the colors to change based on the theme the user picks, I am unsure if I should make separate materials for each theme, or just one material for each prefab, and just change the albedo through code. What is better practice?
I'm definitely not one for best practices, though I would assume that multiple materials would be more expensive than doing it via code... I'm trying to think of an efficient way to go about it though. Perhaps have each object query a "theme controller" as to what it's colour should be. something like:
private void Start()
{
//Get required bits
Renderer rend = GetComponent<Renderer>();
themeCon = GameObject.FindGameObjectWithTag("ThemeController");
//set required bits
rend.material.shader = Shader.Find("_Color");
rend.material.SetColor("_Color", themeCon.SquareColor);
}
Then within that theme controller, have a number of variables for each type of object
public string SquareColor;
public string HexagonColor;
public string CircleColor;
private void Start()
{
//Default Values
SquareColor = "red";
HexagonColor = "blue";
CircleColor = "yellow";
}
void Theme1()
{
SquareColor = "black";
HexagonColor = "grey";
CircleColor = "purple";
}
void Theme2()
{
SquareColor = "green";
HexagonColor = "pink";
CircleColor = "blellow"; //Reese was a genius.
}
Then finally, have some sort of GUI that would call whichever theme you wanted. Of course none of the code I wrote here is actually usable, but I think something along those lines would work... you could also look at using JSON to store your themes, then have each object look in there to see what colour it should be based on the current theme. I've yet to delve in to working with JSON, though I do know that it would be more flexible in the long run since you wouldn't need to add another method for each theme. And would probably be easier than my contrived method.
Wow, thanks for the help. I think I will do what you said with the theme controller.
I am still relatively new to Unity, it has JSON? Isn't that a web-language?
Your answer