物体需要带有Collider组件,2D的类似
void Start () { Collider[] colliders = Physics.OverlapSphere (transform.position, 3); foreach (Collider c in colliders) { if (c.gameObject != this.gameObject) { Debug.Log (c.gameObject.name); } } }
Physics.OverlapSphere(中心,半径)表示检测在中心点和半径组成的圆内的物体们
2D类似,Sphere球形,还有其他的形状,自行查看API
overlap n.重叠