Last active
April 22, 2020 21:10
-
-
Save BanksySan/e30638246eb95d8f34b402327ed8b40e to your computer and use it in GitHub Desktop.
Blog - Mark Center andExtents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using static UnityEditor.Handles; | |
using static UnityEngine.Color; | |
using static UnityEngine.Gizmos; | |
[ExecuteAlways] | |
[RequireComponent(typeof(Renderer))] | |
public class MarkCenterAndExtents : MonoBehaviour | |
{ | |
private const float RADIUS = 0.02f; | |
private GUIStyle _labelStyle; | |
private Renderer _renderer; | |
private void Start() | |
{ | |
_renderer = GetComponent<Renderer>(); | |
_labelStyle = new GUIStyle | |
{ | |
fontSize = 40, | |
fontStyle = FontStyle.Bold, | |
contentOffset = new Vector2(20, 0) | |
}; | |
} | |
private void OnDrawGizmos() | |
{ | |
var bounds = _renderer.bounds; | |
Gizmos.color = white; | |
Vector2 center = bounds.center; | |
DrawSphere(center, RADIUS); | |
Label(center, $"Centre: {center}", _labelStyle); | |
Gizmos.color = red; | |
Vector2 extents = bounds.extents; | |
DrawSphere(extents, RADIUS); | |
Label(extents, $"Extent: {extents}", _labelStyle); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment