Unity Collider Bounds and extents 調試


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestPhyCollider : MonoBehaviour
{
    public Collider tree;

    public Vector3 scale = new Vector3(0.3f, 0.3f, 0.3f);
    public bool isExtent;
    public bool isSize;

    public void OnCollisionEnter(Collision other)
    {
    }

    public void OnDrawGizmos()
    {
        Gizmos.DrawCube(tree.bounds.center, scale);

        Gizmos.color = Color.blue;
        Gizmos.DrawCube(tree.bounds.max, scale);
        Gizmos.color = Color.yellow;
        Gizmos.DrawCube(tree.bounds.min, scale);

        if (isExtent)
        {
            Gizmos.color = Color.magenta;
            Gizmos.DrawCube(tree.bounds.center, tree.bounds.extents);
        }

        if (isSize)
        {
            Gizmos.color = Color.gray;
            Gizmos.DrawCube(tree.bounds.center, tree.bounds.size);
        }

        //下面一個點
        var center = tree.bounds.center;
        center.y = tree.bounds.min.y;
        Gizmos.DrawCube(center, scale);
        
        //后面一個點
        var center2 = tree.bounds.center;
        center2.z = tree.bounds.min.z;
        Gizmos.DrawCube(center2, scale);
        
        //前面一個點
        var center3 = tree.bounds.center;
        center3.z = tree.bounds.max.z;
        Gizmos.DrawCube(center3, scale);
        
        //左邊一個點
        var center4 = tree.bounds.center;
        center4.x = tree.bounds.min.x;
        Gizmos.DrawCube(center4, scale);
        
        //右邊一個點
        var center5 = tree.bounds.center;
        center5.x = tree.bounds.max.x;
        Gizmos.DrawCube(center5, scale);
        
    }
}

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM