Unity Bound

Posted huangzhenxiong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity Bound相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

Unity报错:Read only asset Packages/com.xxxxx.xxx.xxxx/Editor/VSCodeDiscovery.cs.IPGSD has no meta(代码片段

Unity中获取Animator中动画片段的时长

unity动画一个片段播放完怎么让它不会到初始状态

csharp Unity C#片段用于将变换旋转到新的相对旋转数秒

unity 优化整理

unity 优化整理