From 005229e2c33892ba23336f6e65b3a16c4f2fccec Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 5 Oct 2019 13:13:26 +0200 Subject: [PATCH] Add SlowlyDisappear component --- Assets/Components/SlowlyDisappear.cs | 33 +++++++++++++++++++++++ Assets/Components/SlowlyDisappear.cs.meta | 11 ++++++++ Assets/Prefabs/Gravitation Object.prefab | 14 ++++++++++ 3 files changed, 58 insertions(+) create mode 100644 Assets/Components/SlowlyDisappear.cs create mode 100644 Assets/Components/SlowlyDisappear.cs.meta diff --git a/Assets/Components/SlowlyDisappear.cs b/Assets/Components/SlowlyDisappear.cs new file mode 100644 index 0000000..a9f60a8 --- /dev/null +++ b/Assets/Components/SlowlyDisappear.cs @@ -0,0 +1,33 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SlowlyDisappear : MonoBehaviour +{ + public float disappearAfter; + protected float timeLeft; + protected SpriteRenderer sprite; + + protected float FractionLeft { + get { + return timeLeft / disappearAfter; + } + } + + private void Start() { + sprite = GetComponent(); + timeLeft = disappearAfter; + } + + private void Update() { + timeLeft -= Time.deltaTime; + + if(sprite != null) { + sprite.color = new Color(sprite.color.r, sprite.color.g, sprite.color.b, FractionLeft); + } + + if(timeLeft < 0) { + Destroy(this.gameObject); + } + } +} diff --git a/Assets/Components/SlowlyDisappear.cs.meta b/Assets/Components/SlowlyDisappear.cs.meta new file mode 100644 index 0000000..4a20196 --- /dev/null +++ b/Assets/Components/SlowlyDisappear.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8cb7610d172100841907b194dece1565 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Gravitation Object.prefab b/Assets/Prefabs/Gravitation Object.prefab index eeac4e8..645cef6 100644 --- a/Assets/Prefabs/Gravitation Object.prefab +++ b/Assets/Prefabs/Gravitation Object.prefab @@ -13,6 +13,7 @@ GameObject: - component: {fileID: 5473375028011702753} - component: {fileID: 5473375028011702752} - component: {fileID: 5473375028011702755} + - component: {fileID: 5319285082587561044} m_Layer: 0 m_Name: Gravitation Object m_TagString: Untagged @@ -135,6 +136,19 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: positionInList: 0 +--- !u!114 &5319285082587561044 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5473375028011702754} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8cb7610d172100841907b194dece1565, type: 3} + m_Name: + m_EditorClassIdentifier: + disappearAfter: 5 --- !u!1 &8635663089806839545 GameObject: m_ObjectHideFlags: 0