This question was
closed May 29, 2016 at 11:11 PM by
PCgee for the following reason:
The question is answered, right answer was accepted
Question by
PCgee · May 30, 2016 at 07:37 AM ·
c#programmingarraysvariables
Assigning array values to variables
I am trying to make it so that I create a gameobject from a prefab at a certain x value in my game. I have an array that stores all the possible x values (it is lane based it has to start at one of these x values) and I am trying to take a random number from that array and setting it as the x value when I instantiate the prefab.
private float metPosX;
public int metPosY;
private float[] metPositons;
// Use this for initialization
void Start () {
metPositons = new float[9] { -11.99336F, -8.994928F, -5.9965F, -2.990871F, 0.0003575F, 2.998786F, 5.998786F, 8.995644F, 11.994017F };
}
// Update is called once per frame
void Update () {
int xArrayIndex = Random.Range(0, 8);
metPosX = metPositions[xArrayIndex];
}
public Transform meteorPrefab;
public void newMeteor() {
Vector3 meteorPos = new Vector3(metPosX, metPosY, 0);
Instantiate(meteorPrefab, meteorPos, Quaternion.identity);
}
I keep getting the error that "The name "metPositions" does not exist in the current context" any help would be greatly appreciated.
Comment