- Home /
Making objects invisible
So I am trying to make a game object invisible in unity using a if statement to turn it off but nothing happens if I use the following: if (Input.GetKeyDown (KeyCode.M)) { Bed.GetComponent().enabled = false; Bed.GetComponent().enabled = false; } I have it in the update function provided in c# scripts by default. I also used the following in my code which still does nothing: Bed.gameObject.SetActive(false);
I have tried a bunch of other lines suggested in forum posts but they either give me errors or seem to do nothing. I would appreciate if someone could help me because I am rather new to unity and have been trying to fix this for a couple days.
Answer by Az_Rieils · Dec 10, 2018 at 10:48 PM
Hey. Why not try something like
if ( Input.GetKeyDown (KeyCode.M) ) {
Debug.Log("I hit the button M! Im so cool! Maybe i dont do it before" );
this.gameObject.setActive(false);
// or
// Bed.setActive(false);
// Bed.GetComponent<MeshRenderer>().enabled = false
// Bed.transform.scale.set( Vector3.zero );
// etc
}
And can you attach inspector of you bed?
Answer by EbicGamer · Dec 11, 2018 at 11:03 PM
![alt text][1]
This is what it looks like if I use the vector scale. I get errors, otherwise nothing happens. DebugLog works @Az_Rieils [1]: /storage/temp/129291-no.jpg