From aef8b147be8084d60bdc917b75ac689461da2c6a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 5 Oct 2019 13:30:09 +0200 Subject: [PATCH] Use a gradient for the color change --- Assets/Components/SlowlyDisappear.cs | 5 ++-- Assets/Prefabs/Gravitation Object.prefab | 29 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Assets/Components/SlowlyDisappear.cs b/Assets/Components/SlowlyDisappear.cs index a9f60a8..9f296ce 100644 --- a/Assets/Components/SlowlyDisappear.cs +++ b/Assets/Components/SlowlyDisappear.cs @@ -5,6 +5,7 @@ using UnityEngine; public class SlowlyDisappear : MonoBehaviour { public float disappearAfter; + public Gradient colorCurve; protected float timeLeft; protected SpriteRenderer sprite; @@ -21,9 +22,9 @@ public class SlowlyDisappear : MonoBehaviour private void Update() { timeLeft -= Time.deltaTime; - + if(sprite != null) { - sprite.color = new Color(sprite.color.r, sprite.color.g, sprite.color.b, FractionLeft); + sprite.color = colorCurve.Evaluate(FractionLeft); } if(timeLeft < 0) { diff --git a/Assets/Prefabs/Gravitation Object.prefab b/Assets/Prefabs/Gravitation Object.prefab index 645cef6..4e81eae 100644 --- a/Assets/Prefabs/Gravitation Object.prefab +++ b/Assets/Prefabs/Gravitation Object.prefab @@ -149,6 +149,35 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: disappearAfter: 5 + colorCurve: + serializedVersion: 2 + key0: {r: 1, g: 0, b: 0, a: 0} + key1: {r: 1, g: 1, b: 1, a: 1} + key2: {r: 1, g: 0.82856506, b: 0.82856506, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65535 + ctime2: 21203 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 --- !u!1 &8635663089806839545 GameObject: m_ObjectHideFlags: 0