- Home /
Change the background color attribute of a camera in C#?
0 Hey! So, I'm working on a 2D game, and I'd need to change the background color of the main camera, but I just can't figure out the syntax. I'm making this game in C# and I'd need to have it change from an OnTriggerEnter2D function. Thanks! :D
PS. Keep in mind, this is a repost, because my other one got closed. There is a background color attribute in the Unity editor, which you can change in a color selection field, but how can I change it in a script in C#? Here is a picture for clarification:
Answer by GiyomuGames · Aug 12, 2015 at 05:56 AM
I think this should help you: http://docs.unity3d.com/ScriptReference/Camera-backgroundColor.html
Thanks so much! Just one thing: Can i replace Color.Blue, Color.Red etc. with a Hex value?
Unity doesn't internally support hex BUT what you can do is write the function yourself:
http://answers.unity3d.com/questions/812240/convert-hex-int-to-colorcolor32.html
O$$anonymous$$ then, I Probably wouldnt understand how to use that, so I'll stick with the normal colors. I didn't need it to be hex specifically, only I wanted more control from the base colors. Will it work with RGB, or some other more accurate system?
What do you mean? The link I gave you gives a function for converting Hex to Colors. RGB is the base color system. I don't think you can get more accurate than that in Unity.
You can use RGB by doing: new Color(Rvalue, Gvalue, Bvalue), you can also put the alpha as a 4th parameter. Please keep in $$anonymous$$d that all values must be between 0 and 1. http://docs.unity3d.com/ScriptReference/Color.html
Answer by allenallenallen · Aug 12, 2015 at 05:55 AM
This is the syntax:
http://docs.unity3d.com/ScriptReference/Camera-backgroundColor.html
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Randomly Transition Camera Background Color? 2 Answers
Making a camera semi-orthographic 2 Answers