using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;
[RequireComponent(typeof(LineRenderer))]
public class LineEdit : MonoBehaviour
{
public AnimationCurve X,Y,Z;
public int Count;
public Vector3 StartPoint,EndPoint;
private LineRenderer _lineRender;
/// <summary>
/// Awake is called when the script instance is being loaded.
/// </summary>
void Awake()
{
_lineRender = GetComponent<LineRenderer>();
}
// Start is called before the first frame update
void Start()
{
resetPos();
}
private void resetPos()
{
_lineRender.positionCount = Count;
NativeArray<Vector3> positions = new NativeArray<Vector3>(Count,Allocator.Temp);
for (int i = 0; i < Count; i++)
{
float t = (float)i/(Count-1);
Vector3 pos = Vector3.Lerp(StartPoint,EndPoint,t);
pos.x += X.Evaluate(t);
pos.y += Y.Evaluate(t);
pos.z += Z.Evaluate(t);
positions[i]=pos;
}
_lineRender.SetPositions(positions);
}
}
|