diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/Unparent.cs |
+ init
Diffstat (limited to 'GameCode/Unparent.cs')
-rw-r--r-- | GameCode/Unparent.cs | 44 |
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); + } +} |