Gui slider for transparency from 0 till 100

As the title says i’m in need of a GUI slider that changes my 3d objects transparency from 0 till 100 depending on the slider i know the code to change my materials transparency but how do i connect that to the slider?

color.a = 0;

thanks guys

use a GUI.HorizontalSlider…

then have it set the alpha directly…

//var viewObject : Transform;
var hSliderValue = 1.0;

function OnGUI () {
	hSliderValue = GUI.HorizontalSlider (Rect (25, 25, 100, 30), hSliderValue, 0.0, 1.0);
	renderer.material.color.a=hSliderValue;
	//viewObject.renderer.material.color.a=hSliderValue;
}

Can anyone tell me how to do this with c# please? I was following a tutorial trying to convert this piece of code

 public void ToggleAlpha(float minV, float maxV)
	{
		if(renderer.material.color.a > minV  decr)                //Works fine
			renderer.material.color.a -= 1*Time.deltaTime;    //Doesn't work
		else
			renderer.material.color.a += Time.deltaTime;      //Doesn't work
		
		
		
		if(renderer.material.color.a > maxV  decr)               //Works fine
			decr = true;
		else if(renderer.material.color.a < minV)                    //Works fine
			renderer.material.color.a += Time.deltaTime;    //Doesn't work
	}

I don’t remember what the error was at the moment. I think it was something along the lines of its trying to a value into nothing and it doesn’t like it. So it tells me to store it into a temp variable.

Because Material.color is a property that returns a value type, you can’t manipulate the elements of the returned value directly in that way. You can however write something like this (untested):

var color = renderer.material.color;
color.a = ...;
renderer.material.color = color;

I’d recommend wrapping this up in a function if you need to do it more than once.

You might be able to create an extension method for the Material class or even the Color class. You can keep it in context better that way.