Hello every one!
I need help with changing my alpha on a material to 0.5 over time.
This event will occur when a ball rolls into a specific zone and a windmill
are suppose to be half transparent while the ball is in that zone.
Im using toon shaders with outlines, but when collission happens the shader will first change to a shader with alpha values, at the moment the code works but with no lerp/change over time.
My code so far:
var Windmill : GameObject; // Put Windmill mesh here in the inspector
var WindmillBlades : GameObject; // Put Windmill blades here
var WindmillMotor : GameObject; // Put Windmill motor here
var ToonAlpha : Shader; //Add shader in inspector - the one with alpha
var ToonNonAlpha : Shader; //Add shader in inspector - the one with no alpha and outlines
function Start () {
}
function OnTriggerEnter (c : Collider)
{
if (c.CompareTag("Player"))
{
Windmill.renderer.material.shader = ToonAlpha;
WindmillMotor.renderer.material.shader = ToonAlpha;
WindmillBlades.renderer.material.shader = ToonAlpha;
Windmill.renderer.material.color.a = 0.5; // 50 % transparent, I want this to lerp.
WindmillMotor.renderer.material.color.a = 0.5; // 50 % transparent, I want this to lerp.
WindmillBlades.renderer.material.color.a = 0.5; // 50 % transparent, I want this to lerp.
}
}
function OnTriggerExit (c : Collider)
{
if (c.CompareTag("Player"))
{
WindmillBlades.renderer.material.color.a = 1.0; // fully opaque , I want this to lerp.
WindmillMotor.renderer.material.color.a = 1.0; // fully opaque, I want this to lerp.
Windmill.renderer.material.color.a = 1.0; // fully opaque, I want this to lerp.
WindmillBlades.renderer.material.shader = ToonNonAlpha;
WindmillMotor.renderer.material.shader = ToonNonAlpha;
Windmill.renderer.material.shader = ToonNonAlpha;
}
}
function Update () {
}
Sadly I have no Idea how to make it work, not so good with lerp and such things.
I have tried some lerping but all in vain, and I dont know If I should have
my “ontrigger” inside the update function for stuff to work with “Time.deltaTime”.
Thank you for helping out 
Try this tutorial, it deals with intensity but should give you some hints 
http://unity3d.com/learn/tutorials/modules/beginner/scripting/lerp
Time.DeltaTime is a publicly accessible static property. realistically you can get to it from anywhere, but there are very specific cases where you should never need to get it (off hand FixedUpdate as this is time independent therefore you shouldn’t need to reference time).
though I am not directly clear on what you mean by OnTriggerXXX inside update (stab in dark) probably mean that the logic of the OnTriggerXXX in Update if this is true then yes.
if you attempted to do a lerp inside the OnTriggerXXX (except for stay) then you will not get a lerp to work; because OnTriggerEnter is called the frame immediately after the collision has occurred with a trigger, and OnTriggerExit is called the frame immediately after the collision has stopped with a given trigger. basically you would be doing on iteration of a change function (most change functions need to be called repeatedly either until they are complete, or some condition that they need to stop.)
try placing the change logic in the Update, or a co-routine, and just add control logic to the OnTriggerXXX
A big THANK YOU guys!
Now I got a working code for half transparency, both ways 
When you leave the collider the opacity goes up as well and it looks nice.
var Windmill : GameObject; // Put Windmill mesh here in the inspector
var WindmillBlades : GameObject; // Put Windmill blades here
var WindmillMotor : GameObject; // Put Windmill motor here
var ToonAlpha : Shader; //Add shader in inspector - the one with alpha
var ToonNonAlpha : Shader; //Add shader in inspector - the one with no alpha and outlines
var makeTransparent = 0;
var smooth = 0.01;
function Start () {
}
function OnTriggerEnter (c : Collider)
{
if (c.CompareTag("Player"))
{
Windmill.renderer.material.shader = ToonAlpha;
WindmillMotor.renderer.material.shader = ToonAlpha;
WindmillBlades.renderer.material.shader = ToonAlpha;
makeTransparent = 1;
}
}
function OnTriggerExit (c : Collider)
{
if (c.CompareTag("Player"))
{
makeTransparent = 2;
}
}
function Update () {
if (makeTransparent == 1)
{
IntensityChanging();
}
else if (makeTransparent == 2)
{
IntensityChanging2();
}
}
function IntensityChanging ()
{
Windmill.renderer.material.color.a = Mathf.Lerp(Windmill.renderer.material.color.a, 0.5, smooth*Time.deltaTime);
WindmillMotor.renderer.material.color.a = Mathf.Lerp(Windmill.renderer.material.color.a, 0.5, smooth*Time.deltaTime);
WindmillBlades.renderer.material.color.a = Mathf.Lerp(Windmill.renderer.material.color.a, 0.5, smooth*Time.deltaTime);
}
function IntensityChanging2 ()
{
Windmill.renderer.material.color.a = Mathf.Lerp(Windmill.renderer.material.color.a, 1.0, smooth*Time.deltaTime);
WindmillMotor.renderer.material.color.a = Mathf.Lerp(Windmill.renderer.material.color.a, 1.0, smooth*Time.deltaTime);
WindmillBlades.renderer.material.color.a = Mathf.Lerp(Windmill.renderer.material.color.a, 1.0, smooth*Time.deltaTime);
if (Windmill.renderer.material.color.a >= 0.99)
{
WindmillBlades.renderer.material.shader = ToonNonAlpha;
WindmillMotor.renderer.material.shader = ToonNonAlpha;
Windmill.renderer.material.shader = ToonNonAlpha;
makeTransparent = 0;
}
}