Import mesh and show it

I made the following code to import a mesh. The compiler claims that no MeshImporter isn’t a member of UnityEngine.Mesh. What can I do to create the wanted feature?

var MeshObj : Mesh = Mesh.MeshImporter(“3001”);//name of the imported meshObject
var Vector : Vector3 = new Vector3( 3, 0, 2 );

if(GUI.Button(Rect(25, 65, 80, 20), “MeshButton”)){
Graphics.DrawMesh ( MeshObj, Vector, Quaternion.LookRotation);
}

You don’t actually need to write any code at all to import or draw a mesh. You merely need to put the mesh asset file (.fbx, .mb, .ma, .blend, etc) into your Project View. Unity will then automatically import the mesh and keep it available to you in the Project View. To draw the mesh, you simply instantiate the asset object by dragging the file from Project View into your Scene View or Hierarchy View.

For more information about importing mesh asset files, please see this page: http://unity3d.com/support/documentation/Manual/Meshes.html

If you haven’t done so already, please take a read through the “Learning the Interface” section of the manual: http://unity3d.com/support/documentation/Manual/Learning%20the%20Interface.html

I allready read all of the manuals. But they don’t seem to give me the answer.
If I drag the object into the Project View and then into my Scene View, then I guess the object will be viewable from the beginning of runtime? THis isn’t the desired solution. The object should ONLY be visible when I push a button during runtime.

var object : Transform;

function OnGUI () {
if(GUI.Toggle(Rect(25, 65, 80, 20), "MeshButton")){
if (!MeshObj) {
MeshObj = Instantiate (object, Vector, Quaternion.LookRotation);
}
}
else {
if (MeshObj) Destroy(MeshObj);
}
}

You really can’t expect Unity to have a button to do something like this for you. You will need to use a script… the above script, probably. :wink:

Probably easier if you just have the object’s renderer set to disabled at the beginning. Then do object.renderer.enabled = true when you want it to show up. Instead of the mesh thing.

–Eric

I didn’t expect a button to do the job just like that. I expect a script or some other code to do the job. I just didn’t have a clue on how to do the code or the script. But I’ll try to implement the solution that is show lastly.

As written in the last reply I thought about having all of the objects in the View at runtime, too. Just to make them invisible and then if the user chooses the object from a button then a clone of the object will become visible. That was one of my ideas to implement today. Is that what you sugested, Erik?

By the way what I did yesterday was to try to use this:

Graphics.DrawMesh( mesh2, Vector3 ( 3, 0, 2 ), qa);

But I didn’t get anywhere with that. The main problem was the last argument (qa). I don’t know what or how to solve that.

I’m trying to implement the solution from

Eric5h5
Joined: 19 Jul 2006
Posts: 1985

But I’m having trouble refering to my object through the script. How do I get the reference to my object in the script?