Hi everyone,
it’s been asked once before but the advice to restart Unity does not work for me
When CoordinateLabeler is active I can’t rename GameObjects in the scene hierarchy. I can do it in the inspector but I am curious as to what causes this behaviour.
I can select the object in the hierarchy, press F2 and it looks like I instantly lose focus of the text field.
The script is basically what Gary is showing us in the lecture:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
[ExecuteAlways]
public class CoordinateLabeler : MonoBehaviour {
TextMeshPro label;
Vector2Int coordinates = new Vector2Int();
private void Awake() {
label = GetComponent<TextMeshPro>();
DisplayCoordinates();
}
void Update() {
if (!Application.isPlaying) {
DisplayCoordinates();
UpdateObjectName();
}
}
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();
}
}
Anyone got an idea? Using Unity 2020.3.32f1