Update Self Destruct Script

This commit is contained in:
Philip W 2021-11-01 20:09:52 +00:00
parent ad095108d1
commit 05311b5b2d
2 changed files with 33 additions and 14 deletions

View File

@ -1,29 +1,37 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
public class TimedSelfDestruct : MonoBehaviour public class TimedSelfDestructWithTimer : MonoBehaviour
{ {
// After this time, the object will be destroyed // After this time, the object will be destroyed
public float timeToDestruction; public float timeToDestruction;
void Start () void Start()
{ {
Invoke("DestroyMe", timeToDestruction); //Invoke("DestroyMe", timeToDestruction);
} }
// Update is called every frame, if the MonoBehaviour is enabled. // Update is called every frame, if the MonoBehaviour is enabled.
void Update() void Update()
{ {
if (timeToDestruction > 0)
{
timeToDestruction -= Time.deltaTime;
GetComponentInChildren<TextMesh>().text = Mathf.Abs(timeToDestruction).ToString();
}
else
{
DestroyMe();
}
} }
// This function will destroy this object :( // This function will destroy this object :(
void DestroyMe() void DestroyMe()
{ {
Destroy(gameObject); Destroy(gameObject);
// Bye bye! // Bye bye!
} }
} }

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7fb007fc909a54d4e9f2700296b8898d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: