Is there such thing as a TRIPLE ARRAY?
I have an int from another class, and the class is called PlayerScript1, and I am retrieving the int called "gameLevel" to get the current level, where I store it in the int localGameLevel. That data is checked in the animalLevelData1 list, where it scans what animals need to spawn in the scene. Then, I have another called "animalSpeed1" and this is the problem. It stores how fast the animal goes, depending what slot in the list that it is in. The code is animalLevelData1[animalLevelData1[localGameLevel]] because I am trying to retrieve data from another set of data. I keep getting the error: IndexOutOfRangeExeption: Array Index Out of Range. Is it not possible to retrieve data like that? or is there another solution? Any feedback is greatly appreciated. Thanks!
public int[] animalLevelData1;
public int[] animalSpeed1;
private int localGameLevel;
transform.position = new Vector3 (predatorPos.x +=
animalLevelData1[animalLevelData1[localGameLevel]],predatorPos.y,predatorPos.z);
void getLevel()
{
player = GameObject.Find ("Player1");
localGameLevel = player.GetComponent<PlayerScript1> ().gameLevel;
}
Answer by ShadyProductions · Jul 02, 2017 at 07:27 PM
The error means there is no such index in the given array for example:
int[] abc = new int[2];
abc[3] = 5; //index out of range because 3 does not exist
This is the case for you:
animalLevelData1[animalLevelData1[localGameLevel]]
either the index of localGameLevel
in animalLevelData1[localGameLevel]
does not exist in your animalLevelData1
or it does exist the int and when you give the new int to animalLevelData1
again, it doesn't exist.
Wow! This really helped. Thank you so much! I wasn't able to reward you with many points, as I am fairly new to Unity and answers.unity3d.com, but I gave you what I could give you. Thanks again, @ShadyProductions! You really helped me out!
Your answer

Follow this Question
Related Questions
how to check the bool of multiple object in an arrya. 0 Answers
Checking if a point is withing any of the colliders 1 Answer
Array 2D of data 1 Answer