Skip to content

Instantly share code, notes, and snippets.

@enpel
Last active August 29, 2015 14:15
Show Gist options
  • Save enpel/26baa531ea74ecad7425 to your computer and use it in GitHub Desktop.
Save enpel/26baa531ea74ecad7425 to your computer and use it in GitHub Desktop.
GameObjectの拡張どっこいしょ
using UnityEngine;
using System.Collections;
public static class GameObjectExtensions
{
// GameObjectの子にいるGameObjectを名前で取得する
public static GameObject FindChild (this GameObject parent, string name)
{
Transform child =parent.transform.Find(name);
return child == null ? null : child.gameObject;
}
// 子供を全員Destroy!KillThemALL!!!(DestroyAllChildrenとかの方がわかりやすいと思います
public static void KillChildrenAll(this GameObject current)
{
foreach ( Transform n in current.transform )
{
GameObject.Destroy(n.gameObject);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment