This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
When game starts I want to add X gameobject as a child of some Y parent gameobject,
But before it is added, I want to check if there is already any child gameobject. If there is then I want to destroy it and add new X gameobject. I made some code but it seems not to work as I want it to.
if(levelsParent.transform.childCount > 0)
l = levelsParent.GetComponentsInChildren<Transform>();
foreach (Transform li in l)
{
if(li)
{
GameObject.Destroy(li.gameObject);
}
}
GameObject lt = Instantiate(levelTemplates[cardLevel - 1]);
Subreddit
Post Details
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/Unity3D/com...