Public accessable type class array

Hi, topic says all ! Im doing some build/farming game and it has build menu , where i can choose building to be placed and builded.

I made my decision to have class Gobject

public class GObject{
	var name : String;
	var Width : int;
	var Heigth : int;
	var description : String;
}

And i want that to be array. I can do such a thing in VB , but some how in JS i can’t… And that array must be PUBLIC so i can acces it everywhere !

Please help me !

Thank you

var gObjects : GObject[];

–Eric

This dosen’t help, how i can acces that array from … other script ?

If this helps anyone, i got my code working. I can have public static array of class types and i can even modify their value in inspector. Here is code:
BuildManager.js

#pragma strict


var Gobj : GObject[];
public static var GameObjects : GObject[];


function Start()
{
 
 var Count : int = 0;
 GameObjects = new GObject[Gobj.length];
 
 for (i in Gobj)
 {
 	 print(i.name);
	 GameObjects[Count] = i;
	 Count++; 
 }
}

And this is how you acces it from other script :


unction OnGUI () {
	// Make a background box
	GUI.Box (Rect (10,10,100,90), "Build menu");

	// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
	if (GUI.Button (Rect (20,40,80,20), "Choose building")) {
		print(BuildManager.GameObjects[0].name);
	}

	
}

You typically use GetComponent to access public variables from other scripts. I wouldn’t recommend using a static variable like that, because then you have duplicate arrays for no good reason.

–Eric

Using GetComponent will have much higher function call times than straight array access. Having two arrays isn’t really problem, and they are filled on start of program so it dosent impact perfomance !

Not really; if you’re using GetComponent that frequently then you’d cache the call, so performance wouldn’t be an issue. Having two separate arrays and copying the contents is just making things a lot messier than they should be.

–Eric