x


How to attach a mesh created with Graphics.DrawMesh to a GameObject?

I'm making a game where the player has to draw lines. I'm using Graphics.DrawMesh, but I can't find a way to convert the line into a GameObject. I need it to be a GameObject because it needs to detect collisions.

PS: This might be stupid, but I'm pretty new with Unity.

Thanks in advance!

more ▼

asked Jul 06 '12 at 07:43 PM

kennyomar gravatar image

kennyomar
3 1 1

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

1 answer: sort voted first

You will probably have to do it procedurally. Try something like this:

var newObj : GameObject = new GameObject(objectName);
				newObj.AddComponent(MeshFilter);
				newObj.AddComponent(MeshRenderer);
	
				var mesh = new Mesh (); // <---- the mesh you created
				newObj.GetComponent(MeshFilter).mesh = mesh;
more ▼

answered Jul 06 '12 at 08:37 PM

Jake Haas gravatar image

Jake Haas
106 1

Thanks a lot Jake!

Jul 10 '12 at 09:45 PM kennyomar
(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:

x2097
x492
x80
x16

asked: Jul 06 '12 at 07:43 PM

Seen: 381 times

Last Updated: Jul 10 '12 at 09:45 PM