The tile labels disappear and do not toggle if the C key is pressed while in Play Mode. Seems like a bug. Here’s my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System;
[ExecuteAlways]
public class CoordinateLabeler : MonoBehaviour
{
[SerializeField] Color defaultColor = Color.white;
[SerializeField] Color blockedColor = Color.gray;
TextMeshPro label;
Vector2Int coordinates = new Vector2Int();
Waypoint waypoint;
private void Awake()
{
label = GetComponent<TextMeshPro>();
label.enabled = false;
waypoint = GetComponentInParent<Waypoint>();
DisplayCoordinates();
}
private void Update()
{
if (!Application.isPlaying)
{
DisplayCoordinates();
UpdateObjectName();
}
ColorCoordinates();
ToggleLabels();
}
void ToggleLabels()
{
if(Input.GetKeyDown(KeyCode.C))
{
label.enabled = !label.IsActive();
}
}
void ColorCoordinates()
{
if (waypoint.IsPlacable)
{
label.color = defaultColor;
}
else
{
label.color = blockedColor;
}
}
void DisplayCoordinates()
{
coordinates.x = Mathf.RoundToInt(transform.parent.position.x / UnityEditor.EditorSnapSettings.move.x);
coordinates.y = Mathf.RoundToInt(transform.parent.position.z / UnityEditor.EditorSnapSettings.move.z);
label.text = coordinates.x + "," + coordinates.y;
}
void UpdateObjectName()
{
transform.parent.name = coordinates.ToString();
}
}
Any help is appreciated; thanks!