how to create a LineRenderer Object with script and attach to the gameObject?

I get the answer about how to attach the prefabs to a Empty gameObject,just set the transfom.parent of the prefabs to the transform of Empty gameObject

and then I want to create the LineRenderer Object with the script:

line:LineRenderer=new LineRenderer();

and the I try to attach this object to the Empty gameObject with script:

line.transform.parent=gameObject.tranform

but its failed,and then

I try to line = gameObject.AddComponent(LineRenderer);

but its also fail to draw the line with two vector3 Object

I wish to get the solution with this question,how to attach the LineRenderer to an EmptyObject and then draw a line with two vector3 object

thanks a lot !

2 Answers

2

No, you aren't doing this right. This is completely wrong:

line:LineRenderer=new LineRenderer();

You want to do:

myGameObject.AddComponent(LineRenderer);

You also need to set up the line renderer's vertices and positions using SetVertexCount() and SetPosition().

Make sure you read this page in full: http://unity3d.com/support/documentation/ScriptReference/LineRenderer.html

22666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666