Stratasys-450mc-VR/Assets/Scripts/Part Labels/PartLabel.cs
2023-11-03 09:21:55 -04:00

40 lines
1.1 KiB
C#

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);
}
}
}