blob: cc69c83507a4a61e488237dfc529060ae21e487a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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);
}
}
|