Advertisement
ThomasPixel

Untitled

Apr 15th, 2023
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. public abstract class EntityBase : MonoBehaviour
  2. {
  3.     // Entity data
  4.     private string EntityName;
  5.     private Vector2 EntityPosition;
  6.     private int EntityZIndex;
  7.     private float EntityRotation;
  8.     private EntityType EntityType;
  9.     private EntityCategory EntityCategory;
  10.  
  11.     // Debug data
  12.     public Color gizmoColor = Color.red;
  13.     private DebugManager debugger;
  14.     private Vector3 position;
  15.     private string labelText;
  16.  
  17.     private void Start()
  18.     {
  19.         debugger = FindObjectOfType<DebugManager>();
  20.         position = transform.position;
  21.         labelText = "(" + Mathf.Round(position.x) + ", " + Mathf.Round(position.y) + ")";
  22.     }
  23.  
  24.     private void Update()
  25.     {
  26.         if (position != transform.position)
  27.         {
  28.             position = transform.position;
  29.             labelText = "(" + Mathf.Round(position.x) + ", " + Mathf.Round(position.y) + ")";
  30.         }
  31.     }
  32.  
  33.     private void OnDrawGizmos()
  34.     {
  35.         Gizmos.color = gizmoColor;
  36.  
  37.         // Calculate the center, draw cube
  38.         Vector3 tileCenter = new Vector3(Mathf.Round(position.x), Mathf.Round(position.y), 0f);
  39.         Gizmos.DrawWireCube(tileCenter, Vector3.one * 1f);
  40.  
  41.         // Draw a label gizmo above the wire cube with the cached label text
  42.         GUIStyle style = new GUIStyle();
  43.         style.normal.textColor = gizmoColor;
  44.         style.alignment = TextAnchor.MiddleCenter;
  45.         Handles.Label(tileCenter + Vector3.up * 0.6f, labelText, style);
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement