0

您好我正在使用此代码绘制一条跟随对象的线

Debug.DrawLine(new Vector3(gameObject.transform.position.x,     gameObject.transform.position.y, gameObject.transform.position.z),
        new Vector3(prevPosition_x, prevPosition_y, prevPosition_z), Color.red,1.0f);

    prevPosition_x = gameObject.transform.position.x;
    prevPosition_y = gameObject.transform.position.y;
    prevPosition_z = gameObject.transform.position.z;

然而,这并没有在构建中绘制。有谁知道如何在不使用内置线或轨迹渲染器的情况下做到这一点。我知道它可以用 gl 完成,但不知道如何做到这一点。

任何帮助表示赞赏

4

3 回答 3

1

我相信 Debug.DrawLine 只适用于场景编辑器。

有几种方法可以画线,GL绝对是其中之一。还有Vectrosity

唉,您可以通过生成自己的线网格并移动顶点来自己完成。

希望能帮助到你。

于 2013-04-16T14:46:43.093 回答
0

As Xerosigma said, Debug.DrawLine only works in Editor, because it's purpose is to debug scripts, not provide visualization for users. Another problem is that this way, you'll only create lines that will render one frame, and previous to current position will only differ by one frame. You, on the other hand, probably want the trail not to be dependent on framerate.

I think that you'll find TrailRenderer component in Unity fitting for your situation. I've used it in one of my hobbie projects, and it works just fine.

于 2013-04-17T08:32:33.710 回答
0

我认为这不是最好的方法,但应该可以

http://rockonflash.wordpress.com/2010/04/17/how-to-do-lasers-in-unity3d/

Debug.DrawLine 仅适用于场景窗口

于 2013-04-17T18:38:24.477 回答