ソースコード
using UnityEngine;
<summary>
</summary>
public static class ComponentExtensions
{
<summary>
</summary>
public static void RemoveComponent<T>(this Component self) where T : Component
{
GameObject.Destroy(self.GetComponent<T>());
}
}
<summary>
</summary>
public static class GameObjectExtensions
{
<summary>
</summary>
public static void RemoveComponent<T>(this GameObject self) where T : Component
{
GameObject.Destroy(self.GetComponent<T>());
}
}
使い方
var gameObject = new GameObject();
gameObject.AddComponent<BoxCollider>();
gameObject.RemoveComponent<BoxCollider>();
関連記事