x


slider to control shader opacity

I want to use the Unity Compound control example at the top here: file:///Applications/Unity/Unity.app/Contents/Documentation/Documentation/Components/gui-Extending.html (Which needs a curly bracket in it by the way) to control the opacity of a shader. Can anyone point me in the right direction? Thanks.

more ▼

asked Jun 06 '10 at 03:23 PM

Davies gravatar image

Davies
84 6 6 9

So you want to create an editor gui or are your referring to in game.

Jun 06 '10 at 04:06 PM Peter G

I've made a slider using the example from Unities docs. What I want to do is have it control the opacity of an alpha channel in a transparent shader. Thanks.

Jun 06 '10 at 04:40 PM Davies
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

It's pretty easy:

float AlphaValue = 1;

void OnGUI()
{
     AlphaValue = GUI.HorizontalScrollbar(new Rect(0, 0, 100, 20), AlphaValue, 1, 0, 1, "MyScrollbar");
}

void Update()
{
     Color c = renderer.material.color;
     renderer.material.color = new Color(c.r, c.g, c.b, AlphaValue);
}

I realize this sets the color of the shader every frame, so it's not completely efficient, but I figure I'll leave the optimization up to you. :P

more ▼

answered Jun 08 '10 at 11:59 PM

qJake gravatar image

qJake
11.6k 43 78 161

Thank you for that but I'm afraid it doesn't work. Doesn't even generate a slider, and there are a whole raft of errors in the console. Thanks anyway.

Jun 09 '10 at 01:59 PM Davies

The script is in C#, and you need to create your own class header. This isn't a full script. I assumed you knew how to script so I gave you a partial script.

Jun 09 '10 at 09:46 PM qJake
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3816
x109
x3

asked: Jun 06 '10 at 03:23 PM

Seen: 2780 times

Last Updated: Jun 06 '10 at 03:23 PM