Created
August 15, 2016 18:50
-
-
Save CloudyWater/b1012671d2ecc25231fa2859bd899638 to your computer and use it in GitHub Desktop.
Unity 2D Sprite Trail Object
This file contains 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 UnityEngine; | |
using System.Collections; | |
public class DashTrailObject : MonoBehaviour | |
{ | |
public SpriteRenderer mRenderer; | |
public Color mStartColor, mEndColor; | |
private float mDisplayTime; | |
private float mTimeDisplayed; | |
private DashTrail mSpawner; | |
// Use this for initialization | |
void Start () | |
{ | |
} | |
// Update is called once per frame | |
void Update () | |
{ | |
mTimeDisplayed += Time.deltaTime; | |
mRenderer.color = Color.Lerp (mStartColor, mEndColor, mTimeDisplayed / mDisplayTime); | |
if (mTimeDisplayed >= mDisplayTime) | |
{ | |
mSpawner.RemoveTrailObject (gameObject); | |
Destroy (gameObject); | |
} | |
} | |
public void Initiate (float displayTime, Sprite sprite, DashTrail trail) | |
{ | |
mDisplayTime = displayTime; | |
mRenderer.sprite = sprite; | |
mTimeDisplayed = 0; | |
mSpawner = trail; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment