unity3d 如何更改此线渲染器的凹陷位置

inn6fuwd  于 2022-12-13  发布在  其他
关注(0)|答案(1)|浏览(147)

我正在使用下面的代码来绘制一个弯曲的虚线使用线渲染器(从网上复制)。它的工作,但曲线是形成向下像一艘船。我想画的曲线在相反的方向。我试图调整的值,但没有运气。谁能请说如何做这与此代码?或可以建议我一套新的代码
NB-我在编程方面只有非常基础的知识。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DrawLineRenderer : MonoBehaviour
{
    public Transform Point1;
    public Transform Point2;
    public Transform Point3;
    public LineRenderer linerenderer;
    public float vertexCount = 12;
    public float Point2Ypositio = 2;
    // Start is called before the first frame update
    void Start()
    {
        linerenderer.SetWidth(10, 10);
    }

   
    public void buttonPress()
    {
         Point2.transform.position = new Vector3((Point1.transform.position.x + Point3.transform.position.x)/2, Point2Ypositio, (Point1.transform.position.z + Point3.transform.position.z) *2);
        var pointList = new List<Vector3>();

        for(float ratio = 0;ratio<=1;ratio+= 1/vertexCount)
        {
            var tangent1 = Vector3.Lerp(Point1.position, Point2.position, ratio);
            var tangent2 = Vector3.Lerp(Point2.position, Point3.position, ratio);
            var curve = Vector3.Lerp(tangent1, tangent2, ratio);

            pointList.Add(curve);
        }

        linerenderer.positionCount = pointList.Count;
        linerenderer.SetPositions(pointList.ToArray());
    }
    
}
eaf3rand

eaf3rand1#

设定点2Y位置=600

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DrawLineRenderer : MonoBehaviour
{
    public Transform Point1;
    public Transform Point2;
    public Transform Point3;
    public LineRenderer linerenderer;
    public float vertexCount = 12;
    public float Point2Ypositio = 600;
    // Start is called before the first frame update
    void Start()
    {
        linerenderer.SetWidth(10, 10);
    }

   
    public void buttonPress()
    {
         Point2.transform.position = new Vector3((Point1.transform.position.x + Point3.transform.position.x)/2, Point2Ypositio, (Point1.transform.position.z + Point3.transform.position.z) *2);
        var pointList = new List<Vector3>();

        for(float ratio = 0;ratio<=1;ratio+= 1/vertexCount)
        {
            var tangent1 = Vector3.Lerp(Point1.position, Point2.position, ratio);
            var tangent2 = Vector3.Lerp(Point2.position, Point3.position, ratio);
            var curve = Vector3.Lerp(tangent1, tangent2, ratio);

            pointList.Add(curve);
        }

        linerenderer.positionCount = pointList.Count;
        linerenderer.SetPositions(pointList.ToArray());
    }
    
}

相关问题