2019-10-05 11:13:26 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class SlowlyDisappear : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public float disappearAfter;
|
2019-10-05 11:30:09 +00:00
|
|
|
|
public Gradient colorCurve;
|
2019-10-05 11:13:26 +00:00
|
|
|
|
protected float timeLeft;
|
|
|
|
|
protected SpriteRenderer sprite;
|
|
|
|
|
|
|
|
|
|
protected float FractionLeft {
|
|
|
|
|
get {
|
|
|
|
|
return timeLeft / disappearAfter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Start() {
|
|
|
|
|
sprite = GetComponent<SpriteRenderer>();
|
|
|
|
|
timeLeft = disappearAfter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update() {
|
|
|
|
|
timeLeft -= Time.deltaTime;
|
2019-10-05 11:30:09 +00:00
|
|
|
|
|
2019-10-05 11:13:26 +00:00
|
|
|
|
if(sprite != null) {
|
2019-10-05 11:30:09 +00:00
|
|
|
|
sprite.color = colorCurve.Evaluate(FractionLeft);
|
2019-10-05 11:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(timeLeft < 0) {
|
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|