Hi, I’m making an endless runner. In the background I want to have hills spawn in randomly.
So at the moment what I’m trying to do is:
-
Get a random number between 0 and 2
-
Instantiate a hill prefab based on the outcome of that random number.
I’m certain the problem is with the way I’m doing this (“hills_”+hillID) when instantiating. But I can’t seem to find a way to create the prefab name to use in instantiate.
public GameObject hills_0;
public GameObject hills_1;
public GameObject hills_2;
private int hillID;
void Update () {
if (/*conditions*/) {
hillID = Random.Range(0, 2);
Instantiate(("hills_"+hillID), new Vector3(generationPoint.position.x, -2.64f, 0f), transform.rotation);
}
}
I also tried creating a string variable and using that but it didn’t work either.
Would be great if one of you could point me in the right direction.
Thanks