- Home /
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!
Answer by Jake Haas · Jul 06, 2012 at 08:37 PM
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;
Your answer
Follow this Question
Related Questions
Will this script that does drawmeshinstancedprocedural actually work? 0 Answers
Combining animations 1 Answer
DrawMesh (second override) causes runtime errors 0 Answers
Graphics.DrawMeshNow on top of gui elements 1 Answer
How to access full Shuriken simulation mesh for use with DrawMeshNow? 0 Answers