- Home /
3d Models, How to turn invisible
Hey Guys, i have a side-scroller game where my character collides with cubes and they turn invisible, i have gotten a 3d model of a Burger and i want to replace the cube with the burger, BUT the way i have gotten the cube to disappear is by coding the visibility of the cubes like this:
GetComponent(MeshRenderer).enabled = false; GetComponent(BoxCollider).enabled = false;
and i cant work out how to make the 3d model disappear because the image is not stored in the (meshrenderer)
Can anyone help, what am i doing wrong?
If the burger is a 3d model then it will use the $$anonymous$$eshRenderer component. So your code should still apply to the burger object.. You might get an error if the burger doesn't have a box collider though!
I must be importing the model wrong because I just dragged it into the scene and transfered all the data from the cubes to the burger. But the visible part of the burger is not in the mess renderer but is just located in the inspecter at the top of the items field.
Answer by Fattie · Mar 19, 2013 at 07:48 AM
it's just
renderer.enabled = false;
note that for the collider it's simply
collider.enabled = false;
this is on a script that's actually attached to the "thing" in question.
As whebert explains it's more likely you simply want to make the object inactive.
gameObject.SetActive(false);
again this is on a script that's actually attached to the "thing" in question.
If you struggle to get at "other" things ... you want to make "something else" somewhere else inactive or invisible ... then suggest articles on unityGEMS.com for basic beginner help with referring to other game objects, or just read the clear Unity doco "referring to other game objects."
Thanx, it worked. but i had a audio file attached to the game object and it wouldn't work but i changed the audio file to be on the player and adjusted the script and now it works fine. thanx heaps.
Hi there. can you help me? i'm working with my AR project in unity. I used 3Ds max to develop my 3D object. after i export to AR for Android, my 3D objects become transparent. you know how to fix it?
Answer by whebert · Mar 19, 2013 at 02:52 AM
If you are using Unity 3.5, you can call
yourGameObject.SetActiveRecursively(false);
If Unity 4, use the new
youGameObject.SetActive(false);
The code doesnt seem to work, although do i need to change "yourGameObject" to the objects name? when i did that it said that it could not find "Burger". also there is more then 1 murger in the level, they are kind of collectables. will this code still work for what im wanting to do?
Thankyou so much for taking the time to answer these questions.
Sorry, went to bed after submitting the answer, so didn't see your reply till this morning.
Anyway, yes, the "yourGameObject" was only an example - not to be copy/pasted. How you would call SetActive() on the game object depends on where you are calling it from. If you are calling it from a component that is attached to the actual game object you are trying to make invisible, you would simply
gameObject.SetActive(false);
But if you were calling this method from a script located elsewhere, say a $$anonymous$$anager script perhaps, you would call it on the variable that is a reference to the game object you want to make invisible. Anyway...
Answer by davidc · Mar 19, 2013 at 02:39 AM
I must be importing the model wrong because I just dragged it into the scene and transfered all the data from the cubes to the burger. But the visible part of the burger is not in the mess renderer but is just located in the inspecter at the top of the items field.
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Drawing a 3D Mesh (javascript) 1 Answer
Scripting Meshes Subdivision(Javascript) 0 Answers
Create edges for vertices(JS) 1 Answer