Unity 3D:在游戏后面画线 object/record 游戏对象采用的路径?
Unity 3D: draw line behind game object/record path taken by game object?
我正在使用 Google 纸板在 Unity3d 中创建一个 VR 应用程序,并且需要知道如何记录玩家所走的路径(他们正在穿越迷宫)。有没有办法绘制用户采取的路径(可能在控制台中;不在实际游戏中,用户不可见)并将此路径保存为图像?
我需要保存一张图片或仅保存玩家在游戏中所处位置的一行,以便我可以通过电子邮件将此 image/data 发送给玩家..完成此操作的最佳方法是什么?
您需要将 List
中的玩家路径存储为 Vector3
。然后你可以使用 LineRenderer
绘制 line.change LineRenderer 的顶点数量到 List.Count 和 LineRenderer.SetVertexCount
然后遍历列表并更改 [=15= 的位置](loopIndex,playersPo[loopIndex]).
List<Vector3> playerPos = new List<Vector3>();
//Store players positions somewhere
//playerPos.Add(pPos);
//playerPos.Add(pPos);
//playerPos.Add(pPos);
Color red = Color.red;
LineRenderer lineRenderer = gameObject.AddComponent<LineRenderer>();
lineRenderer.material = new Material(Shader.Find("Particles/Additive"));
lineRenderer.SetColors(red, red);
lineRenderer.SetWidth(0.2F, 0.2F);
//Change how mant points based on the mount of positions is the List
lineRenderer.SetVertexCount(playerPos.Count);
for (int i = 0; i < playerPos.Count; i++ )
{
//Change the postion of the lines
lineRenderer.SetPosition(i, playerPos[i]);
}
我正在使用 Google 纸板在 Unity3d 中创建一个 VR 应用程序,并且需要知道如何记录玩家所走的路径(他们正在穿越迷宫)。有没有办法绘制用户采取的路径(可能在控制台中;不在实际游戏中,用户不可见)并将此路径保存为图像?
我需要保存一张图片或仅保存玩家在游戏中所处位置的一行,以便我可以通过电子邮件将此 image/data 发送给玩家..完成此操作的最佳方法是什么?
您需要将 List
中的玩家路径存储为 Vector3
。然后你可以使用 LineRenderer
绘制 line.change LineRenderer 的顶点数量到 List.Count 和 LineRenderer.SetVertexCount
然后遍历列表并更改 [=15= 的位置](loopIndex,playersPo[loopIndex]).
List<Vector3> playerPos = new List<Vector3>();
//Store players positions somewhere
//playerPos.Add(pPos);
//playerPos.Add(pPos);
//playerPos.Add(pPos);
Color red = Color.red;
LineRenderer lineRenderer = gameObject.AddComponent<LineRenderer>();
lineRenderer.material = new Material(Shader.Find("Particles/Additive"));
lineRenderer.SetColors(red, red);
lineRenderer.SetWidth(0.2F, 0.2F);
//Change how mant points based on the mount of positions is the List
lineRenderer.SetVertexCount(playerPos.Count);
for (int i = 0; i < playerPos.Count; i++ )
{
//Change the postion of the lines
lineRenderer.SetPosition(i, playerPos[i]);
}