- Home /
color setting in inspector
Hey, I want a variable containing a color in my script but I want to be able to choose it in the inspector like in this picture
How can I create a variable like this in a script that works like a color but is setted in the inspector like this
Tyvm!!
Answer by rezki · Jan 16, 2015 at 06:20 PM
// C#
public Color myColor;
// JavaScript
public var myColor : Color;
Answer by Sabre-Runner · Jan 21, 2018 at 07:56 AM
In Unity, when using C#, it is recommended to never use the 'public' prefix on fields at all. Private fields should be private, obviously. If you want to expose a field in the Inspector, use '[SerializeField] private' as this won't expose it to other scripts, just the inspector. And if you want to open a field up to other scripts, use a public Property which you can control and sanitise to your heart's content.
That's such a BS answer. If you want to use public then use public. You may have cases where its serializable AND need access from other scripts. If you don't wanna waste code in getters.