unity trigger 获取触发点

2D

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.GetComponent<AttackBox>())
        {
            hitPos = other.bounds.ClosestPoint(transform.position);
            print("碰撞点" + hisPos);
        }
    }

 

3D

other.gameObject.GetComponent<Collider>().ClosestPointOnBounds(transform.position);

 

注意这种方法不推荐单场景里过多使用,会产生大量的GC 影响帧率

 

posted @ 2020-04-22 17:21  三页菌  阅读(2285)  评论(0编辑  收藏  举报