mirror of
https://github.com/Steffo99/gravity-fusion.git
synced 2024-11-22 08:24:17 +00:00
34 lines
743 B
C#
34 lines
743 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class SlowlyDisappear : MonoBehaviour
|
|
{
|
|
public float disappearAfter;
|
|
public Gradient colorCurve;
|
|
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;
|
|
|
|
if(sprite != null) {
|
|
sprite.color = colorCurve.Evaluate(FractionLeft);
|
|
}
|
|
|
|
if(timeLeft < 0) {
|
|
Destroy(this.gameObject);
|
|
}
|
|
}
|
|
}
|