I’m aware variables can’t be declared at run time but I’m hoping to be able to reference one that’s already compiled. Let me explain the situation:
I’m generating a 2.5d side scrolling level. I start with a straight piece (a tile). I’ve set up an array saying which pieces are compatible with the tile (another straight, or an end cap).
This is what I have right now and I think it will explain much better than I could with words:
void StageBuilder()
{
for(int i = 0; i < tileCount; i++)
{
Transform thisTile = nextTile[Random.Range (0,nextTile.Length)];
Transform startTile = Instantiate(thisTile, tileStart, Quaternion.Euler(270f, 0f, 0f)) as Transform;
tileStart.x -= 6f;
string hackProgramming = thisTile.name+"Arr";
nextTile = hackProgramming as Transform;
}
}
The resulting string would be the name of the array with compatible pieces. From there, I’d be able to pick another tile randomly and repeat the process.