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

 

相关文章:

  • 2021-10-29
  • 2022-02-21
  • 2021-12-14
  • 2022-01-31
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-25
  • 2022-01-25
  • 2022-12-23
  • 2022-12-23
  • 2021-04-06
  • 2021-05-25
  • 2021-07-22
相关资源
相似解决方案