Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Fade an object in and out

$
0
0
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; } } }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>