var lamps : GameObject[];

Is there a way to make a script utilize the inspector to set the number of input gameobjects that will count under the variable “lamps” while simultaneously setting the number of input gameobjects under the inspector window?

here is my script;

var lamp1: GameObject;
var go : GameObject;
var cur1 : GameObject;
var cur2 : GameObject;
var cur3 : GameObject;
var cur4 : GameObject;
var cur5 : GameObject;
var cur6 : GameObject;
var stlightsBool = false;
var windowRect0 : Rect = Rect (500,10,200,400);

function OnGUI () {
	windowRect0 = GUI.Window (0, windowRect0, wind, "City Controls");
	//GUI.FocusWindow (0);
	}
	function wind (windowID : int){
	
	 
	
stlightsBool = GUI.Toggle (Rect (10, 20, 100, 20), stlightsBool, "Street Lights");


if (stlightsBool == true) lamp1.active = true;
if (stlightsBool == false) lamp1.active = false;


	if (GUI.Button (Rect (10,50,150,50), "Current Layout")) {
		
		go.active = false;
		cur1.active = true;
		cur2.active = true;
		cur3.active = true;
		cur4.active = true;
		cur5.active = true;
		cur6.active = true;
		
		}

	if (GUI.Button (Rect (10,110,150,50), "Hotel Proposal")) {
	
		go.active = true;
		cur1.active = false;
		cur2.active = false;
		cur3.active = false;
		cur4.active = false;
		cur5.active = false;
		cur6.active = false;
		
	}
}

what I want to be able to do is save myself a whole lot of time, see I have 17 lamps at the moment that I want to turn the point lites off for, because you cannot activate a prefab, the only way I know if is to create a variable for each one, it would be nice to set the size (number of lamps) in the unity inspector and then have that many gameobject variable inputs created so i can drag and drop each point light, does this make since?

I haven’t understood everything. When you write something like, var lamp : GameObject[ ], you can define a size in the Inspector. You can redefine the size during play, by giving the variable something like : new GameObject [enter the new size here].

Did I answer you ? :slight_smile: (this fat bird is very dumb…)

Yeah, you use var lamps : GameObject[ ]

That lets you resize and assign to it and everything.

You could also use

lamps = GameObject.FindObjectsOfType( PointLight )

or whatever type the lamps are.

Thank you for the replies…

I tried var lamps : GameObject[ ]

and got an error, which made me think iw as using it wrong. The error reads

I don’t get this error when i use the active call on any static variables, why should it matter ?

It also does not show a size int in the inspector, or any other sign of this scripting variable

I’ll use this for now;

…it might be a better approach for what I want to do anyways, but I would really like to learn the GameObject[ ] approach for future reference

You can’t use .active on an array variable; you have to loop through the array and use .active on each entry.

It does:

var lamps : GameObject[];

That shows in the inspector and you can set the size.

–Eric

could you give me a hint on how to do this or where I could find it in the scripting reference so I can learn it

var lamps : GameObject;

isn’t registering in my script, in fact I changed the var lamp1 : GameObject; to var lamps : GameObject; and the name change of the variable doesn’t even update in my inspector, it must be because of the error it is throwing at me.

You would use a loop like this:-

for (i = 0; i < lamps.Length; i++) {
  lamps[i].active = false;
}

If the lamps array isn’t showing up in the inspector, the first thing to check is that you are not getting any error messages. You need to fix all errors before any changes to the script will be reflected in the inspector.

your loop get a error,you have to fix with:

for (i in lamps) {
  i.active = false;
}