【发布时间】:2020-05-31 12:52:41
【问题描述】:
The reference of a trajectory line
嘿,我是 Unity 新手,我试图在线条渲染器的帮助下创建轨迹线,但它似乎不起作用。我在下面附上了我的运动脚本。如果有人帮助我,那将非常有帮助。
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);
}
}
【问题讨论】:
-
忽略我试图做的 for 循环而不是线渲染器,但这也不起作用。
标签: c# unity3d game-development