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);
}
}
LineRender曲线脚本
最新推荐文章于 2024-09-01 08:30:37 发布
该博客介绍了一个Unity脚本LineEdit,它利用AnimationCurve来动态控制LineRenderer组件,实现从起始点到终点的平滑曲线路径。通过调整X、Y、Z属性的AnimationCurve,可以改变路径在三个轴上的变化,从而创建出各种复杂的3D路径效果。
摘要由CSDN通过智能技术生成