我知道有一些功能,如lineRenderer等,但我想在场景中使用两个点(以Vector3形式)创建一条直线。我不想使用任何键或鼠标来绘制线条,我只想在触发某些事件时或单击“播放”按钮后立即在场景中看到线条。

谁能帮我?

最佳答案

//For creating line renderer object
lineRenderer = new GameObject("Line").AddComponent<LineRenderer>();
lineRenderer.startColor = Color.black;
lineRenderer.endColor = Color.black;
lineRenderer.startWidth = 0.01f;
lineRenderer.endWidth = 0.01f;
lineRenderer.positionCount = 2;
lineRenderer.useWorldSpace = true;

//For drawing line in the world space, provide the x,y,z values
lineRenderer.SetPosition(0, new Vector3(x,y,z)); //x,y and z position of the starting point of the line
lineRenderer.SetPosition(1, new Vector3(x,y,z)); //x,y and z position of the starting point of the line

关于unity3d - 如何使用两个Vector3点统一创建一条线?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19236482/

10-09 00:03