About Showing Gizmo on the same Collider position and rotation :)

To draw a box gizmo is pretty tricky, indeed about the rotation, I’ve dig a bit about it, and at the end I’ve found a solution, so I’ve extended our code so we can have a boxGizmo with the same size of the BoxCollider, but we can choose the color from inspector too.

[SerializeField] Color boxColor = new Color(.09f, .4f, .8f, .5f);
// the rest of your code
// and then...
 private void OnDrawGizmos()
        {
            Gizmos.color = boxColor;
            Gizmos.matrix = transform.localToWorldMatrix; //that's for the box rotation
            Gizmos.DrawCube(GetComponent<BoxCollider>().center, GetComponent<BoxCollider>().size);
        }
2 Likes

Well done!

1 Like

Privacy & Terms