How to make an object invisible

I’ve been trying to use the following code to make objects invisible:

renderer.enabled = false;

However it doesn’t make any difference and is still visible in the scene.
I need it working so that if the players objective is 0, the objective is invisible but if the player’s objective is 1 or higher, the object becomes visible again.

![alt text][1]
[1]: http://25.media.tumblr.com/tumblr_marg19JK751qjvatjo1_500.png

What I want is to make the chain of the mug disappear until the first objective is complete, but at the moment the code isn’t working. Could someone make an example Unity project of like a disappearing cube?

Most of my project is using Javascript. Not sure if this is what’s causing all the problem or if it’s something else.

Problem solved. Thanks for the help everyone :slight_smile:

Hi Alex,

I made an example scene for you:

https://dl.dropbox.com/u/107533178/DissapearingCubeExample.zip

There is a script on the camera that accesses the cubes renderer. Really basic stuff.

Cheers!

Mithos

I’m going to assume you made the same mistake I did when I first started using Unity; you have a GameObject with a bunch of children inside of it. You need to disable the renderers of all the children!

Here’s an example script that will make the object visible or invisible depending on whether or not “isVisible” is true:

var isVisible : boolean = true;

function Update(){
	
	if(isVisible){
		var allMyRenderers = GetComponentsInChildren(Renderer);
		for (var renderer : Renderer in allMyRenderers) {
			renderer.enabled = false;
		}
	}
 	else{
		var allMyRenderers = GetComponentsInChildren(Renderer);
		for (var renderer : Renderer in allMyRenderers) {
			renderer.enabled = true;
		}
	}

}

This will loop through all of the object’s renderers and disable 'em. To make them visible again, use the same code but with ‘true!’

You can always set the local scale of the gameobject to 0 if memory is not the problem…
gameObject.transform.localScale = Vector3(0,0,0);