T
T
Tterka2021-07-30 14:28:45
C++ / C#
Tterka, 2021-07-30 14:28:45

How to remove object instead of transform?

Trying to remove children:
int x = 0;
for (x=transform.childCount;x>0;x--)
{
var obj =transform.GetChild(0);
Destroy(obj);
}
It doesn't work because I'm trying to remove the transform
how do I remove the object itself?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2021-07-30
@Tterka

Destroy(....gameObject)

C
Crebor, 2021-07-31
@Crebor

Destroy(gameObject, 5); 5 - time in seconds
Destroy(gameObject); will be destroyed immediately
https://docs.unity3d.com/ScriptReference/Object.De...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question