From 05311b5b2dd925c96c4c249f33846d03c6791c44 Mon Sep 17 00:00:00 2001 From: Philip White Date: Mon, 1 Nov 2021 20:09:52 +0000 Subject: [PATCH] Update Self Destruct Script --- .../Gameplay/TimedSelfDestructWithTimer.cs | 36 +++++++++++-------- .../TimedSelfDestructWithTimer.cs.meta | 11 ++++++ 2 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 Unity-Files/Assets/Scripts/Gameplay/TimedSelfDestructWithTimer.cs.meta diff --git a/Unity-Files/Assets/Scripts/Gameplay/TimedSelfDestructWithTimer.cs b/Unity-Files/Assets/Scripts/Gameplay/TimedSelfDestructWithTimer.cs index 4f22f12..3a06f03 100644 --- a/Unity-Files/Assets/Scripts/Gameplay/TimedSelfDestructWithTimer.cs +++ b/Unity-Files/Assets/Scripts/Gameplay/TimedSelfDestructWithTimer.cs @@ -1,29 +1,37 @@ using UnityEngine; using System.Collections; -public class TimedSelfDestruct : MonoBehaviour +public class TimedSelfDestructWithTimer : MonoBehaviour { - // After this time, the object will be destroyed - public float timeToDestruction; + // After this time, the object will be destroyed + public float timeToDestruction; - void Start () - { - Invoke("DestroyMe", timeToDestruction); - } + void Start() + { + //Invoke("DestroyMe", timeToDestruction); + } // Update is called every frame, if the MonoBehaviour is enabled. void Update() { - + if (timeToDestruction > 0) + { + timeToDestruction -= Time.deltaTime; + GetComponentInChildren().text = Mathf.Abs(timeToDestruction).ToString(); + } + else + { + DestroyMe(); + } } - // This function will destroy this object :( - void DestroyMe() - { - Destroy(gameObject); + // This function will destroy this object :( + void DestroyMe() + { + Destroy(gameObject); - // Bye bye! - } + // Bye bye! + } } diff --git a/Unity-Files/Assets/Scripts/Gameplay/TimedSelfDestructWithTimer.cs.meta b/Unity-Files/Assets/Scripts/Gameplay/TimedSelfDestructWithTimer.cs.meta new file mode 100644 index 0000000..fb6e91b --- /dev/null +++ b/Unity-Files/Assets/Scripts/Gameplay/TimedSelfDestructWithTimer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7fb007fc909a54d4e9f2700296b8898d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: