1
Fork 0
mirror of https://github.com/Steffo99/gravity-fusion.git synced 2024-11-22 08:24:17 +00:00
gravity-fusion/Assets/Components/SlowlyDisappear.cs

35 lines
743 B
C#
Raw Normal View History

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);
}
}
}