x


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 !

more ▼

asked Sep 23 '10 at 03:16 PM

solo gravatar image

solo
1 2 2 4

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Sep 23 '10 at 09:12 PM

qJake gravatar image

qJake
11.6k 43 78 161

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x107

asked: Sep 23 '10 at 03:16 PM

Seen: 3399 times

Last Updated: Sep 23 '10 at 03:16 PM