- Home /
 
               Question by 
               Red Sentinel · Apr 25, 2013 at 05:25 AM · 
                materialrendererdisableenable  
              
 
              Fade an object in and out
Hi everyone. I have a script that when the player presses the RendererOnOff button which is e, objects tagged with Player will change material and when e is released it will go back. Objects tagged with WorldObject will become invisible and when e is released they become visible. I was wondering if there was a way to gradually disable the renderer and change the material, say over 1 second or so. This would just add a nice effect to what I have. Thanks for any input.
 var StartMaterial : Material;
 var UpdateMaterial : Material;
 
 
 function Start () {
     if (gameObject.tag == "Player"){
         renderer.material = StartMaterial;
     }
 }
 
 function Update () {
     if (gameObject.tag == "WorldObject"){
         if (Input.GetButtonDown ("RendererOnOff")){
             renderer.enabled = false;
         }
         if (Input.GetButtonUp ("RendererOnOff")){
             renderer.enabled = true;
         } 
     }
     if (gameObject.tag == "Player"){
         if (Input.GetButtonDown ("RendererOnOff")){
             renderer.material = UpdateMaterial;
         }
         if (Input.GetButtonUp ("RendererOnOff")){
             renderer.material = StartMaterial;
         }
     }
 }
               Comment
              
 
               
              Hello, $$anonymous$$aybe you could try with the color.lerp function http://docs.unity3d.com/Documentation/ScriptReference/Color.Lerp.html you change the color of your material from it's first color to color.clear. Not sure about the result :p just an idea which come by.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                