color GUI

ey got a little question…
how do i get that when i press on a character (object/collider) he opens a GUI.
and then in the GUI is standing:
“e bob wanna change hair color ?”
and under it are 5 buttons with : brown grey blue black white and light brown
and when you press it changes the material of you hair…
can someone help me with that ?

You could use that, so when a person clicks it, that calls a GUI management object to change state which will then open up a color dialogue which then passes the color back to the object to change its material color.

and you can change the material color by using Material.color function.

i cant get something out of it… :frowning:

Well, nobody is going to just write your code for you.

If you cannot work with that, then your goal is too high for your current skill. That’s easy to solve, you merely have to break it down into bite-sized pieces. Start with just making OnMouseDown Debug.Log() something. Also, you’ll need to have each object have its own collider, right? Put two and two together with that.

If you’re looking to change a material altogether I’d recommend having a look at this particular part of the scripting reference guide. Unity - Scripting API: Renderer

You’ll be looking at something like this (code below) for swapping a texture on an object… this also means you’re going to have to have separate 2D textures for all of the various hair colours, though it shouldn’t be to bad if you only have a couple of colour choices.

Code example…

//Attach to Main Camera
var elCharacto : Transform;//OBJECT WITH RENDERER TO BE CHANGED GOES HERE!

var redTex : Texture2D;
var yellowTex : Texture2D;
var blueTex : Texture2D;

var showred : boolean = false;
var showyellow : boolean = false;
var showblue : boolean = false;

function Update () {
	if (showred) {
		elCharacto.renderer.sharedMaterial.mainTexture = redTex;
	}
	if (showyellow) {
		elCharacto.renderer.sharedMaterial.mainTexture = yellowTex;
	}
	if (showblue) {
		elCharacto.renderer.sharedMaterial.mainTexture = blueTex;
	}
}

Please note: I have used ‘sharedMaterial’, rather than ‘material’ - sharedMaterial will change every instance of the material in the scene. Please change it to ‘material’ if you only have the one instance.

I am at this point in time working on something similar to what you described in your first post, but on a much more elaborate scale (using GUI sliders). If it works, and I’m feeling generous I may post it on the forums for everyone to enjoy.