码迷,mamicode.com
首页 > 编程语言 > 详细

在Unity中如何取得一个Box的Bounds

时间:2015-04-04 16:45:18      阅读:651      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

    private BoxCollider mCollider;
    // Use this for initialization
    void Start ()
    {
        mCollider = GetComponent<BoxCollider> ();
        Bounds bounds = mCollider.bounds;

        Vector3 boundPoint1 = bounds.min;
        Vector3 boundPoint2 = bounds.max;
        Vector3 boundPoint3 = new Vector3 (boundPoint1.x, boundPoint1.y, boundPoint2.z);
        Vector3 boundPoint4 = new Vector3 (boundPoint1.x, boundPoint2.y, boundPoint1.z);
        Vector3 boundPoint5 = new Vector3 (boundPoint2.x, boundPoint1.y, boundPoint1.z);
        Vector3 boundPoint6 = new Vector3 (boundPoint1.x, boundPoint2.y, boundPoint2.z);
        Vector3 boundPoint7 = new Vector3 (boundPoint2.x, boundPoint1.y, boundPoint2.z);
        Vector3 boundPoint8 = new Vector3 (boundPoint2.x, boundPoint2.y, boundPoint1.z);
// rectangular cuboid
        // top of rectangular cuboid (6-2-8-4)
        Debug.DrawLine (boundPoint6, boundPoint2, Color.green, int.MaxValue);
        Debug.DrawLine (boundPoint2, boundPoint8, Color.green, int.MaxValue);
        Debug.DrawLine (boundPoint8, boundPoint4, Color.green, int.MaxValue);
        Debug.DrawLine (boundPoint4, boundPoint6, Color.green, int.MaxValue);
        
        // bottom of rectangular cuboid (3-7-5-1)
        Debug.DrawLine (boundPoint3, boundPoint7, Color.red, int.MaxValue);
        Debug.DrawLine (boundPoint7, boundPoint5, Color.red, int.MaxValue);
        Debug.DrawLine (boundPoint5, boundPoint1, Color.red, int.MaxValue);
        Debug.DrawLine (boundPoint1, boundPoint3, Color.red, int.MaxValue);
        
        // legs (6-3, 2-7, 8-5, 4-1)
        Debug.DrawLine (boundPoint6, boundPoint3, Color.yellow, int.MaxValue);
        Debug.DrawLine (boundPoint2, boundPoint7, Color.yellow, int.MaxValue);
        Debug.DrawLine (boundPoint8, boundPoint5, Color.yellow, int.MaxValue);
        Debug.DrawLine (boundPoint4, boundPoint1, Color.yellow, int.MaxValue);
    }

 

在Unity中如何取得一个Box的Bounds

标签:

原文地址:http://www.cnblogs.com/eran/p/4392349.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!