Skip to content

Commit

Permalink
Simplified DrawBounds so that it stops throwing error when filter is …
Browse files Browse the repository at this point in the history
…not initialized;
  • Loading branch information
hugoscurti committed Aug 6, 2018
1 parent 66abb22 commit 52add43
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions Assets/Scripts/DrawBounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,17 @@

public class DrawBounds : MonoBehaviour {

private new MeshRenderer renderer;
private MeshFilter filter;

// Use this for initialization
void Start () {
renderer = GetComponent<MeshRenderer>();
filter = GetComponent<MeshFilter>();
}

void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
if (renderer != null && enabled)
if (enabled)
{
Matrix4x4 rotationMatrix = Matrix4x4.TRS(transform.position, transform.rotation, transform.lossyScale);
Gizmos.matrix = rotationMatrix;
Gizmos.DrawWireCube(filter.mesh.bounds.center, filter.mesh.bounds.size);

// This is the renderer's bounds, which is less accurate if we account rotations
//Gizmos.DrawWireCube(renderer.bounds.center, renderer.bounds.size);
if (!filter) filter = GetComponent<MeshFilter>();
var modelMatrix = Matrix4x4.TRS(transform.position, transform.rotation, transform.lossyScale);
Gizmos.matrix = modelMatrix;
Gizmos.DrawWireCube(filter.sharedMesh.bounds.center, filter.sharedMesh.bounds.size);
}



}
}

0 comments on commit 52add43

Please sign in to comment.