- Home /
How can I make a GameObject invisible while maintaining its interractivity?
I've found out the correct answer but I don't know how to use it. I saw that I must write this somewhere: GetComponent(MeshRenderer).enabled = false;
The question is where? Where must I write this?
Answer by Jinxology · Jan 29, 2014 at 09:46 PM
You would call that in a MonoScript Component that is on that object. For example, in UnityScript:
function Start() {
GetComponent(MeshRenderer).enabled = false;
}
Click Add Component in the inspector on your object to add a new script component, or by using the top Unity menu system.
Read this, it will help you understand the GameObject/Component relationship.
I can't write this (GetComponent($$anonymous$$eshRenderer).enabled = false;) in the new script because it has foreign characters [();.]
I can only use underscore and letters no other characters
I want to make a gameobject (cube) invisible while I am still able to interract with it (first person controller collide with the cube while on play mode). To do this I must write this somewhere: GetComponent($$anonymous$$eshRenderer).enabled = false;
You told me to go to the cube's inspector and press "Add component", then write this: GetComponent($$anonymous$$eshRenderer).enabled = false; in the bar above "Component" and click "New Script". The problem is that I can't crate this new script because I can only write letters, numbers and underscore (A-Z, a-z, 0-9, _).
Answer by Punkjim420 · Jan 30, 2014 at 11:45 PM
Create a new script and name it something like "MakeInvisible" or "MakeTransparent" then open that script in a text editor like Monodevelop which comes with Unity3D by default. When you open the script in Monodevelop it will have a few premade functions, the first being Function Start() write your code in that function between the {} like this:
Function Start (){ ##Your code goes here## }
if your still lost, i suggest you look at some tutorials, in fact, it might be a good idea to look at them anyways.
I did what you said but nothing happened, the cube was still visible. But never $$anonymous$$d $$anonymous$$d now, when I did it it gave me the "All compiler errors have to be fixed before entering play mode!" error when I pressed play. So I openned the project before writting the script but still the same error occured with this written in the console: Assets/Invisibility.js(5,1): BCE0044: expecting EOF, found '}'. (the script was named Invisibility and I know there was something wrong with this character }) but now the script does not exist but it keeps giving me the error.
Noobfest, honestly, I think you probably need to start with the Unity manual and do some reading to get the basics down: http://docs.unity3d.com/Documentation/$$anonymous$$anual/index.html
Read the basics, learn about GameObjects and Components, etc. I think you are jumping too far ahead based on the dialogue above. You can also go to lynda.com and sign up for a week free, there is an amazing ~11 hour Unity crash course.
Thanks. I guess I was a bit too excited about unity because I started creating villages, I learned how to use box colliders etc... But I guess I have to be patient and get more advanced on it.
Answer by raphel john · Oct 02, 2015 at 09:18 AM
@Noobfest try this man
gameObject.GetComponent().enabled=false;