mirror of
https://udrimavric.com/MAVRIC/Stratasys-450mc-VR.git
synced 2025-01-23 15:48:33 -05:00
42 lines
1.2 KiB
C#
42 lines
1.2 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);
|
|
private LineRenderer lineRenderer;
|
|
private Canvas canvas;
|
|
|
|
private void Start()
|
|
{
|
|
lineRenderer = gameObject.GetComponentInChildren<LineRenderer>();
|
|
canvas = gameObject.GetComponentInChildren<Canvas>();
|
|
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);
|
|
}
|
|
|
|
}
|
|
}
|