renderer and prefab: "enabled" does not work?

Hi,

would you know why this code does not work? Here, “instance” instantiates the prefab, and i would like to hide it, and show it only when i click on the right arrow. But instead it appears at the beginning, would you know how to achieve this?

I added a plane, a light and a character in an empty, and i added a “mesh renderer” to this empty, then i put all of them in a prefab in the “Resources” folder :

Thanks


SOLUTION:

var instance: GameObject;
private var allRenderers : Component[];

function Start () {
	instance = Instantiate(Resources.Load("totalR", GameObject));
	instance.renderer.enabled = false;
	
	allRenderers = instance.GetComponentsInChildren(Renderer);
	for (var aRenderer : Renderer in allRenderers) {
   		aRenderer.enabled = false;
	}
}

function Update () {
	
	if (Input.GetAxis("Horizontal")>0){
		instance.renderer.enabled = true;
		allRenderers = instance.GetComponentsInChildren(Renderer);
		for (var aRenderer : Renderer in allRenderers) {
	   		aRenderer.enabled = true;
		}
	}
}

Uniti has Active function for this. SomeMonoBehaviour.Active(false) - will disable all scripts attached on game object (including render) and all of it’s chields. I gues this is what you need.

PS. Active(bool val) - that’s for unity 4.* for 3.* setActiveRecurseive(bool var) or smh like this, don’t remember)