Created
August 24, 2015 07:44
-
-
Save grimmdev/3864802f96593c1df029 to your computer and use it in GitHub Desktop.
Animates the Alpha on a Renderer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using UnityEngine; | |
| [ExecuteInEditMode] | |
| public class AlphaAnimator : MonoBehaviour | |
| { | |
| [Range(0f, 1f), SerializeField] | |
| private float m_alpha; | |
| private Renderer m_renderer; | |
| private MaterialPropertyBlock m_propBlock; | |
| private void Awake() | |
| { | |
| this.m_propBlock = new MaterialPropertyBlock(); | |
| this.m_renderer = base.renderer; | |
| base.enabled = (this.m_renderer != null); | |
| } | |
| private void Update() | |
| { | |
| if (this.m_renderer != null) | |
| { | |
| Color color = this.m_renderer.sharedMaterial.color; | |
| color.a = this.m_alpha; | |
| this.m_propBlock.Clear(); | |
| this.m_propBlock.AddColor("_Color", color); | |
| this.m_renderer.SetPropertyBlock(this.m_propBlock); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment