Files
aibis-dream/Assets/Scripts/FixSystem/Line/VisualLineSegment.cs
T
2024-08-21 22:13:57 +08:00

37 lines
1002 B
C#

using UnityEngine;
using DG.Tweening;
public class VisualLineSegment : MonoBehaviour
{
public Vector3 StartPoint { get; private set; }
public Vector3 EndPoint { get; private set; }
protected LineRenderer lineRenderer;
protected virtual void Awake()
{
lineRenderer = GetComponent<LineRenderer>();
}
public void Initialize(Vector3 startPoint, Vector3 endPoint)
{
StartPoint = startPoint;
EndPoint = endPoint;
lineRenderer.positionCount = 2;
lineRenderer.SetPosition(0, StartPoint);
lineRenderer.SetPosition(1, EndPoint);
}
public void ShrinkAndDisappear()
{
// Shrink the line segment from the end to the start
DOTween.To(() => EndPoint, x => EndPoint = x, StartPoint, 1f)
.OnUpdate(() => {
lineRenderer.SetPosition(0, StartPoint);
lineRenderer.SetPosition(1, EndPoint);
})
.OnComplete(() => Destroy(gameObject));
}
}