using UnityEngine;
using System.Collections;
public static class GameObjectExtensions
{
public static T GetComponentInParents<T>(this Transform obj) where T : MonoBehaviour, new()
{
Transform parent = obj.transform.parent;
while(parent != null)
{
T res = parent.GetComponent<T> ();
if (res != null)
return res;
parent = parent.parent;
}
return null;
}
}
無限に親を探し続けるので注意…