Everything in this code is working except the toggleLabel fucntion. Can someone please help me fix it?
Im pressing C but the labels are not toggling on and off
using UnityEngine;
using TMPro;
[ExecuteAlways]
public class CoordinateSystem : MonoBehaviour
{
[SerializeField] Color defaultColor = Color.white;
[SerializeField] Color blockedColor = Color.red;
Vector2Int coords = new Vector2Int();
TextMeshPro label;
Waypoint waypoint;
void Awake()
{
label = GetComponent<TextMeshPro>();
label.enabled = false;
waypoint = GetComponentInParent<Waypoint>();
displayCoordinates();
}
void Update()
{
if (!Application.isPlaying)
{
displayCoordinates();
updateName();
}
colorCoordinates();
toogleLabels();
}
void colorCoordinates()
{
if (waypoint.IsPlacable)
{
label.color= defaultColor;
}
else if (!waypoint.IsPlacable)
{
label.color= blockedColor;
}
}
void displayCoordinates()
{
coords.x = Mathf.RoundToInt(transform.parent.position.x / UnityEditor.EditorSnapSettings.move.x);
coords.y = Mathf.RoundToInt(transform.parent.position.z / UnityEditor.EditorSnapSettings.move.z);
label.text = coords.x + ", " + coords.y;
}
void toogleLabels()
{
if (Input.GetKeyDown(KeyCode.C))
{
label.enabled = !label.IsActive(); // If label is already enabled, set label to the opposite of whatever the present state is
}
}
void updateName()
{
transform.parent.name = "( "+ coords.x + ", " + coords.y + " )";
}
}