c# - 使用线渲染器制作瞄准轨迹
问题描述
嘿,我是统一的新手,并试图在线条渲染器的帮助下创建轨迹线,但它似乎不起作用。我在下面附上了我的运动脚本。如果有人帮助我,那将非常有帮助。
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);
}
}
解决方案
线渲染的所有位置都没有变换。
所以你不能设置变换的位置。而是使用 lineRenderer.SetPosition 函数来设置线中点的位置以及索引。
推荐阅读
- python - 网格搜索和交叉验证 SVM
- angular - D3 Angular - 错误 TS2349:无法调用类型缺少调用签名的表达式。类型
- android - 是否可以从 python raspberry pi/ubuntu 访问 SD 卡图像或目录
- arrays - 如何将数组的每个元素压缩到ruby中另一个数组的每个元素?
- java - 试图调用方法我得到 java.lang.IndexOutOfBoundsException
- google-photos - Google Photo API - 按名称获取文件
- javascript - 将图像变量传递给数据库
- c# - 使用 XmlUriResolver 为远程共享提供凭据
- javascript - React hook useEffect 永远/无限循环连续运行
- database - 您如何在数据库关系模式中处理递归关系 N:M