duck

duck

May 20th, 2010
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class LifeTime : MonoBehaviour {
  5.  
  6.     private Color colorStart;
  7.     private Color colorEnd;
  8.     private float duration = 1.0f;
  9.         private float startTime;
  10.    
  11.     void Awake() {
  12.         colorStart = renderer.material.color;
  13.         colorEnd = colorStart;
  14.         colorEnd.a = 0;
  15.                 startTime = Time.time;
  16.     }
  17.    
  18.     void Update () {
  19.         float lerp = Mathf.PingPong (Time.time - startTime, duration) / duration;
  20.         gameObject.renderer.material.color = Color.Lerp(colorStart, colorEnd, lerp);
  21.     }
  22.    
  23. }
Advertisement
Add Comment
Please, Sign In to add comment