如何统一通过Line Renderer获得平滑的线条?

问题描述 投票:1回答:1

[Image of Lines taken from u[![enter image description here nity] 2] 2

通过鼠标移动绘制的线条,但是曲线根本不平滑,这种线条看起来非常难看。我试图更改线渲染器的设置,但没有任何帮助。我被困在这里,需要一些支持...下面我也提到了代码... enter image description here

public GameObject linePrefab;
public GameObject currentLine;
public LineRenderer lineRenderer;
public EdgeCollider2D edgeCollider;
public List<Vector2> fingerPosition;
void Update()
{
    if(Input.GetMouseButtonDown(0))
    {
        CreateLine();
    }
    if(Input.GetMouseButton(0))
    {
        Vector2 tempFingerPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        if(Vector2.Distance(tempFingerPos, fingerPosition[fingerPosition.Count -1]) > 0.1f)
        {
            UpdateLine(tempFingerPos);
        }
    }

}
void CreateLine()
{
    currentLine = Instantiate(linePrefab, Vector3.zero, Quaternion.identity);
    lineRenderer = currentLine.GetComponent<LineRenderer>();
    edgeCollider = currentLine.GetComponent<EdgeCollider2D>();
    fingerPosition.Clear();
    fingerPosition.Add(Camera.main.ScreenToWorldPoint(Input.mousePosition));
    fingerPosition.Add(Camera.main.ScreenToWorldPoint(Input.mousePosition));
    lineRenderer.SetPosition(0, fingerPosition[0]);
    lineRenderer.SetPosition(1, fingerPosition[1]);
    edgeCollider.points = fingerPosition.ToArray();
}
void UpdateLine(Vector2 newFingerPos)
{
    fingerPosition.Add(newFingerPos);
    lineRenderer.positionCount++;
    lineRenderer.SetPosition(lineRenderer.positionCount - 1, newFingerPos);
}
c# unity3d findbugs
1个回答
0
投票

[尝试在在线渲染器上使用的材质上放置纹理。纹理在下面。它在这里看起来是白色的,但是如果您在新标签页中打开它,将会看到。这将有助于在线边界上使用别名。

line texture

© www.soinside.com 2019 - 2024. All rights reserved.