So, I have 8 game Objects that have a 3 digit number as name. Each gameObject has attached an instance of the same script, the script being called bikeAvail.
the contents of bikeAvail.js are as follows:
var bike1 : float;
var bike2 : float;
var bike3 : float;
var bike4 : float;
var bike5 : float;
var bike6 : float;
var bike7 : float;
var bike8 : float;
var bike9 : float;
var bike10 : float;
var bike11 : float;
var bike12 : float;
var bike13 : float;
var bike14 : float;
var bike15 : float;
var bike16 : float;
var bike17 : float;
var bike18 : float;
var bike19 : float;
var bike20 : float;
var bike21 : float;
Basically I just declare the variables, and I want to assign the values later. Furthermore, I have an empty gameObject named bikeController that acts as a controller, and it parses through a csv file, getting the unique values. The aim of the controller is to assign the correct value to every one of the vars in the 8 gameObjects during Start. bikeController has a script with some double for loops to read through the csv array. Part of the script inside the for loop is this:
for (i = 0; i < bikes.GetLength(0); i++) {
for (j = 0; i < bikes.GetLength(1); i++) {
if (j==1) GameObject.Find("109").GetComponent(bikeAvail).bike1 = avail;
And of course this is where things get ugly. The line
if (j==1) GameObject.Find("109").GetComponent(bikeAvail).bike1 = avail;
works fine in accessing the bike1 var in gameObject 109. The problem is that it gives it the value that is intended for bike21 (actually that’s expected, since during the whole for loop I keep accessing the same var). What I want to do is go through the vars in sequence, and do something like this:
for (i = 0; i < bikes.GetLength(0); i++) {
for (j = 0; i < bikes.GetLength(1); i++) {
var bikeName : String = "bike"+i;
if (j==1) GameObject.Find("109").GetComponent(bikeAvail).bikeName = avail;
When I try the above code I get the error: Assets/bikes.js(55,90): BCE0019: ‘bikeName’ is not a member of ‘bikeAvail’.
Any ideas on how I can access variables in other scripts using a string variable instead of a string?
Thanks