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 影响帧率

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM