Hey.
Ok here’s the thing.
I have an object that uses a material that I setup in Unity editor,but the material has no opacity.
It is a simple diffuse material.
But at runtime I do in fact want to change the opacity of the object.
Does Unity already have standard script commands that allow you to change the opacity of an object at runtime,even if the material that is attached to your object does not have an opacity input ?
Opacity doesn’t work with the default diffuse material. You will need to set the material to use the transparent/diffuse shader in order for opacity to work. Use the alpha channel to set the level of opacity required (range 0 to 1).
This code will lerp the alpha channel
var alphaStart : float = 0.0;
var alphaEnd : float = 1.0;
var duration : float = 1.0;
function Update() {
var lerp : float = Mathf.PingPong(Time.time,duration)/duration;
renderer.material.color.a = Mathf.Lerp(alphaStart,alphaEnd,lep);
}
I believe that you are looking for the color alpha…
function Update () {
renderer.material.color.a=Time.time-Mathf.Floor(Time.time);
}