Hiding Assets

Hi everyone,

I’m not usually a person who asks for answers (Yeah, go make the joke about me asking everyone for people join my team) but here we go…

I want to hide all the assets (This includes things like lights) through scripting. I understand I probably need to use tags or something like that, but not sure where to start.

Anybody fancy whipping me up a pseudo script that I can play around with?

Thanks,

Alex

Would this help? Attach it to an empty game object in the scene (From head, haven’t tested it)

private var LightList: GameObject[];
private var currentLight : int = 0;
var Light : GameObject;

// creates an array of all objects tagged as "Light"
function Start(){
LightList = GameObject.FindGameObjectsWithTag("Light");
}

//waits for the key to be pressed
function Update(){
	if (Input.GetButtonDown("HideLights")  LightList.length != 0){
		hideLights();
}

// counts all lights and hides them one by one
function hideLights(){
	for (i = 0; i <LightList.length; i++){
	currentLight = (currentLight + 1) % LightList.length;
	Light = LightList[currentLight];
	Light.enabled = false;
	}
}

Don’t forget to tag your objects and to define a key “HideLights” in the Project settings.

Or…
You could attach this script to every Light:

function Update(){
	if (Input.GetButtonDown("HideLights")){
		Light.enabled = false;
}

This enables you to tag your lights differently, as “YellowLight”, “RedLight”, etc. So this code will turn off all the lights and the upper code will hide only the lights with a specific tag.

As you may already know, each gameObject has some kind of renderer component which makes it visible on a screen. Therefore, you have to access a renderer component of a gameObject and disable it. For example,

GameObject.FindWithTag(“Enemy”).GetComponent(Renderer).enabled = false;

You can select a gameObject and look at the Property Inspector to see what kind renderer component it has. For example, you can check for a renderer component for meshes, particles, lines and trails.