When CoordinateLabeler is in scene i’cant rename objects in hierarchy window
I’m using Unity 2020.3
The code is praticaly the same of the instructor.
Sorry for my bad english. I’m from Brasil and i’m learning english.
here is the code
[ExecuteAlways, RequireComponent(typeof(TextMeshPro))]
public class CoordinateLabeler : MonoBehaviour
{
private TextMeshPro _label;
private Vector2Int _coordinates;
private void Awake()
{
_label = GetComponent<TextMeshPro>();
DisplayCoordinates();
}
private void Update()
{
// ReSharper disable once InvertIf
if (!Application.isPlaying)
{
DisplayCoordinates();
UpdateTileName();
}
}
private void DisplayCoordinates()
{
var position = transform.parent.position;
_coordinates.x = Mathf.RoundToInt(position.x / UnityEditor.EditorSnapSettings.move.x);
_coordinates.y = Mathf.RoundToInt(position.z / UnityEditor.EditorSnapSettings.move.z);
_label.text = $"{_coordinates.x},{_coordinates.y}";
}
private void UpdateTileName()
{
transform.parent.name = _coordinates.ToString();
}
}```