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

Unity Bound

时间:2018-11-11 14:16:52      阅读:340      评论:0      收藏:0      [点我收藏+]

标签:color   enter   object   tran   inspector   void   center   user   start   

Bound:在SpriteRenderer,BoxCollider ,BoxCollider2D,以及mesh中都存在。

其中在SpriteRenderer,BoxCollider ,BoxCollider2D中Bound的Center返回的是Bound的世界坐标。

 

extents:

1.在BoxCollider和BoxCollider2D返回的是scale值

public class Example : MonoBehaviour
{
    Collider m_ObjectCollider;
    public Vector3 m_MyScale;

    void Start()
    {
        //Fetch the GameObject‘s collider (make sure they have a Collider component)
        m_ObjectCollider = gameObject.GetComponent<Collider>();
        //Output the GameObject‘s Collider Bound extents
        Debug.Log("extents : " + m_ObjectCollider.bounds.extents);
    }

    //Detect when the user clicks the GameObject
    void OnMouseDown()
    {
        //Change the scale of the GameObject to the size you define in the Inspector
        transform.localScale = m_MyScale;
        //Output the extents of the Bounds after clicking the GameObject. Extents change to half of the scale.
        Debug.Log("extents : " + m_ObjectCollider.bounds.extents);
    }
}

下面代码可以测试出来。

Unity Bound

标签:color   enter   object   tran   inspector   void   center   user   start   

原文地址:https://www.cnblogs.com/huangzhenxiong/p/9941942.html

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