parentプロパティで一つ上の親オブジェクトを取得することが出来る。
GameObject obj = transform.parent.gameObject;
transform.parent.gameObjectで親を取得。
parentを重ねると親の親を取得できる
GameObject obj = transform.parent.parent.gameObject;
例
public class SphereScript : MonoBehaviour
{
private GameObject testObj;
void Update()
{
if (Input.GetKeyDown(KeyCode.S))
{
testObj = transform.parent.gameObject;
}
}
}