summaryrefslogtreecommitdiff
path: root/GameCode/Unparent.cs
diff options
context:
space:
mode:
Diffstat (limited to 'GameCode/Unparent.cs')
-rw-r--r--GameCode/Unparent.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/GameCode/Unparent.cs b/GameCode/Unparent.cs
new file mode 100644
index 0000000..cc69c83
--- /dev/null
+++ b/GameCode/Unparent.cs
@@ -0,0 +1,44 @@
+using System.Collections;
+using UnityEngine;
+
+public class Unparent : MonoBehaviour
+{
+ public Transform parent;
+
+ public bool follow;
+
+ public float destroyDelay;
+
+ private bool done;
+
+ private void Start()
+ {
+ parent = base.transform.root;
+ }
+
+ private void LateUpdate()
+ {
+ if (!done)
+ {
+ if (base.transform.root != null)
+ {
+ base.transform.SetParent(null, worldPositionStays: true);
+ }
+ if (follow && (bool)parent)
+ {
+ base.transform.position = parent.transform.position;
+ }
+ if (!parent)
+ {
+ StartCoroutine(DelayRemove());
+ done = true;
+ }
+ }
+ }
+
+ private IEnumerator DelayRemove()
+ {
+ yield return new WaitForSeconds(destroyDelay);
+ Object.Destroy(base.gameObject);
+ }
+}