I am new to Unity3d, and I've been watching the tutorials and reading the C# documentation on the Unity website.
But there are some things that I am wondering about and haven't seen them mentioned online.
How can I change the color of a GameObject/Cube/Sphere from within Unity's IDE? I know how to change the color in C#, but I'm hoping there is a way to do it by simply selecting the game object, and then using a Color Picker in the Inspector. But I don't see any options for it.
Answer by pako
Jan 20, 2015 at 08:45 PM
You can only change the colors of a material. This is how it works:
When you create a cube, or a sphere, you add a GameObject that has a MeshFilter component. This , MeshFilter component can hold a mesh, e.g. a cube, a sphere, etc. Although this mesh is present in the scene, it will not be visible, unless it is rendered somehow. This is the job of the MeshRenderer component, and this is why a MeshRenderer component is automatically added together with the MeshFilter component, which holds the mesh. The MeshRenderer component holds a material, and uses this material to render the mesh with a color, a texture, and with other visual qualities specified by a "shader".
However, you need to create a material before you can use it in a renderer. To do that, find the "Create" drop-down in the Project pane, and click Create/material. Give the new material a name, say "red". Then select "red" and in the inspector window you'll see that your new material will have a Diffuse shader. By clicking in the Inspector inside "Main Color", a color picker will pop-up, and you can select the color you want. After that, select your cube and drag-n-drop your new material in "Materials/Element 0" of the MeshRenderer in the Inspector.
After you do that, you can use this same material on as many meshes you want, and if you change the color of the material, any cube, sphere, or other mesh (and corresponding renderer) that uses that material, will change its color as well.
If you add just an empty GameObject, it will not have a mesh or mesh renderer, so you can't add a material, or color like that.
Thank you very much @pako.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
4 People are following this question.
Transparency cube shader?
Changing Cylinder Colour Affects Shader
Material doesn't have a color property '_Color'
Assigning current color to a variable for fade out (C#)
Unable to view colours in game view