I’m brand new to Unity and have read through tutorials but have not ‘clicked’ yet with best practices for manipulating the components of a gameObject.
I have exported three meshes from a max file. Mesh01, Mesh02, Mesh03
I wrote a simple c# script that currently contains information with regards to the individual meshes (Mesh class), but labelled them: Healthy, Damaged, Wreck and then plug in the meshes into the vars. I then have a health var and, for the purposes of testing will slowly reduce till it reaches zero.
My problem is that I am unsure how to control the “Mesh Renderer” for each mesh.
Healthy.enabled and Healthy.renderer do not appear to exist at the mesh level. Any pointers would be helpful :).
Ok, so i think i get what your problem is…
First of all if you only want a GameObject which contains your model so you can add scripts to it i think you should start by using .fbx files instead of max, since they are more simple to manipulate in unity (unity will create a prefab of that model with all you need and you only have to drag and drop it to the scene, it will render automatically).
I Hope this link is helpful:
However according to what i understand you created a script that holds a public “Mesh” type variable and you are trying your .max model into it.
There are 2 important things about this:
- Any script that you are planning to use in the scene must be attatched to a GameObject , you can create a empty one and attatch the script you created into it. (Your script should extend from Monobehavior if you want to use the GameObject properties like “.active”, that disables the gameObject completely from the scene)
- The gameobject that holds the script must have attatched a “Mesh renderer” component in order to render a mesh, you can attatch it from Component->Mesh->MeshRender , also as “whydoidoit” said in another answer you will need a MeshFilter which you can add to your gameObject in Component->Mesh->MeshFilter
You can Enable/Disable the meshfilter like:
After that im a little bit lost to be honest, since i used this approch to dinamycally make meshes, however if you case you have to load your model by hand using Resources.Load (and according to what i think it should be automatically displayed after that).
This second approach will complicate your workflow a lot and also will make you unable to visualize your model while rendering the scene, since you have to Run your script to Load it.
I would stick to using the .fbx files and drag and dropping the prefab
I hope i answered you question and that it helps you in your project!
A MeshRenderer is attached to a GameObject and the mesh it renders is controlled by a MeshFilter that you add to the same GameObject. You can set the mesh of the MeshFilter to cause the MeshRenderer to show a different mesh.