So I don’t know if this can be done, certainly not how I am trying to do it, but there may be another way. Is it possible to combine two values when a script is running to produce a variable name already declared? So as an example:
var enemyShip1 : GameObject;
var enemyShip2 : GameObject;
var enemyShip3 : GameObject;
var enemyShip4 : GameObject;
var enemyShip5 : GameObject;
var enemyShip6 : GameObject;
var enemyShip7 : GameObject;
var enemyShip8 : GameObject;
var shipToSpawn : int = Random.Range (0,9);
function Start () {
var enemy1 = Instantiate (enemyShip+shipToSpawn, triggerPosition.position);
}
The idea being here that the number of the enemyShip that it returns is using the Random.Range at the end of the variable. Of course this returns an immediate error as Unity does not look at the combined value, so doesn’t know what ‘enemyShip’ is on its own. Is this possible in Unity?
But it is combining two values (the random range variable and the array variable name) The value it accesses in the array is taken from a different variable outside the array.