返回层次结构中顶部的 Transform。
(如果此 Transform 没有父级,则此方法永远不会返回 null,它会返回自身。)
using UnityEngine;
public class Example : MonoBehaviour { // Is a collision between two objects with different roots? void OnCollisionEnter(Collision collision) { if (collision.transform.root != transform.root) { print("The colliding objects are not in the same hierarchy"); } } }