56 lines
1.3 KiB
C#
56 lines
1.3 KiB
C#
using Obi;
|
|
using UnityEngine;
|
|
|
|
public class RodLine : MonoBehaviour
|
|
{
|
|
private ObiRope obiRope;
|
|
|
|
private LineRenderer lineRenderer;
|
|
|
|
private Transform[] points;
|
|
|
|
public void GenerateLineRendererRope(Transform[] points, float thickness)
|
|
{
|
|
if (points.Length < 2)
|
|
{
|
|
Debug.LogError("LineRenderer requires at least two points.");
|
|
return;
|
|
}
|
|
|
|
this.points = points;
|
|
if (lineRenderer == null)
|
|
{
|
|
lineRenderer = base.gameObject.GetComponent<LineRenderer>();
|
|
if (lineRenderer == null)
|
|
{
|
|
lineRenderer = base.gameObject.AddComponent<LineRenderer>();
|
|
}
|
|
}
|
|
|
|
lineRenderer.positionCount = points.Length;
|
|
lineRenderer.startWidth = thickness;
|
|
lineRenderer.endWidth = thickness;
|
|
for (int i = 0; i < points.Length; i++)
|
|
{
|
|
lineRenderer.SetPosition(i, points[i].position);
|
|
}
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (lineRenderer == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < points.Length; i++)
|
|
{
|
|
Transform transform = points[i];
|
|
if ((bool)transform)
|
|
{
|
|
lineRenderer.SetPosition(i, transform.position);
|
|
}
|
|
}
|
|
}
|
|
|
|
} |