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