首页 > 解决方案 > 使用线渲染器制作瞄准轨迹

问题描述

轨迹线的参考

嘿,我是统一的新手,并试图在线条渲染器的帮助下创建轨迹线,但它似乎不起作用。我在下面附上了我的运动脚本。如果有人帮助我,那将非常有帮助。

public void Update()
{

    if (Input.GetMouseButtonDown(0)) //press
    {
        startPoint = cam.ScreenToWorldPoint(Input.mousePosition);
        startPoint.z = 15;
        direction = endPoint - startPoint;
        transform.right = direction;

        for (int i = 0; i < numberOfDots; i++)
        {
            trajectoryDots[i].transform.position = calculatePosition(i * 0.01f);
        }
    }

    if (Input.GetMouseButtonUp(0)) //release
    {
        endPoint = cam.ScreenToWorldPoint(Input.mousePosition);
        endPoint.z = 15;

        force = new Vector2(Mathf.Clamp(startPoint.x - endPoint.x, minPower.x, maxPower.x), Mathf.Clamp(startPoint.y - endPoint.y, minPower.y, maxPower.y));
        rb.AddForce(force * power, ForceMode2D.Impulse);
    }

}

标签: c#unity3dgame-development

解决方案


线渲染的所有位置都没有变换。

所以你不能设置变换的位置。而是使用 lineRenderer.SetPosition 函数来设置线中点的位置以及索引。


推荐阅读