首次提交
This commit is contained in:
55
Assets/Scripts/Fishing/Rope/RodLine.cs
Normal file
55
Assets/Scripts/Fishing/Rope/RodLine.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
// 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 (var i = 0; i < points.Length; i++)
|
||||
{
|
||||
var point = points[i];
|
||||
if (point)
|
||||
{
|
||||
lineRenderer.SetPosition(i, point.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user