10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

デバッグ用にバウンディングボックスを表示する

Last updated at Posted at 2017-04-13

unityでオブジェクトの大きさ(絶対値)を知りたい時があるのだが、transformのスケール(相対値)しかわからないっぽいので、以下のようなスクリプトでバウンディングボックスの大きさを確認できるようにしてみた。(ほかに方法があるのか?)

image


using UnityEngine;
using System.Collections;

public class BoundingBoxChecker : MonoBehaviour
{

    [SerializeField] private Vector3 size;
    [SerializeField] private Vector3 center;

    void OnDrawGizmosSelected()
    {

        if (GetComponent<MeshFilter>()==null) return;

        var mesh = GetComponent<MeshFilter>().mesh;
        mesh.RecalculateBounds();

        var bounds = mesh.bounds;

        Gizmos.color = new Color(1, 0, 0, 0.5F);
        Gizmos.DrawCube(bounds.center, bounds.size);

        size = bounds.size;
        center = bounds.center;

    }
}
10
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?