直接贴代码
public Material myMaterisl; float fx;//曲线最左边的X坐标 float fy;//曲线趋于直线时y轴坐标 float fyMax = 0f;//曲线最高点 float fyContunt = 1f;//曲线于y轴坐标的交点 VectorLine energyLine; Vector2[] energyLinePoints; float timer; float energyLevel = 4f; void Start() { fx = 0f; fy = 125f; energyLinePoints = new Vector2[100]; energyLine = new VectorLine("Energy", energyLinePoints, myMaterisl, 5f, LineType.Continuous); fnSetEnergyLinePointsMove(); } void fnSetEnergyLinePoints() { for (int i = 0; i < energyLinePoints.Length; i++) { float x = Mathf.Lerp(70f, 470f, (0.0f + i) / energyLinePoints.Length);//设置点X的坐标 energyLinePoints[i].y = fy * (1f + Mathf.Sin(x) * 0.1f * energyLevel); energyLinePoints[i] = new Vector2(x, energyLinePoints[i].y);//第一次设置点x,y的坐标 } } void fnSetEnergyLinePointsMove() { for (int i = 0; i < energyLinePoints.Length; i++) { float x = Mathf.Lerp(70f, 470f, (i + .0f) / energyLinePoints.Length);//设置点X的坐标 energyLinePoints[i] = new Vector2(x, fy);//第一次设置点x,y的坐标 } } void Update() { } void FixedUpdate() { //让曲线向左运动 int i; for (i = 0; i < energyLinePoints.Length - 1; i++) { energyLinePoints[i].y = energyLinePoints[i + 1].y;//让当前点的y值=它右面点的y值,就是曲线向左移动 } timer += Time.deltaTime * Mathf.Lerp(10.0f, 20.0f, energyLevel); energyLinePoints[i].y = fy * (1f + Mathf.Sin(timer) * .1f * energyLevel); } void LateUpdate() { energyLine.Draw(); }
把脚本添加到摄像机上
运行效果如图: