using UnityEngine; namespace Part_Labels { public class PartLabel : MonoBehaviour { [SerializeField] private GameObject targetPart; [SerializeField] private Vector3 canvasLineOffset = new Vector3(0, -0.04f, 0); [SerializeField] private LineRenderer lineRenderer; [SerializeField] private Canvas canvas; private void Start() { Deactivate(); } [ExecuteAlways] public void Activate() { lineRenderer.gameObject.SetActive(true); lineRenderer.enabled = true; canvas.gameObject.SetActive(true); Vector3 targetPos = targetPart.transform.position; Vector3[] positions = new Vector3[2]; positions[0] = canvas.transform.position+canvasLineOffset; positions[1] = targetPos; lineRenderer.SetPositions(positions); } [ExecuteAlways] public void Deactivate() { canvas.gameObject.SetActive(false); lineRenderer.gameObject.SetActive(false); } } }