Trying to index a list, gives error.
So, I did a void here that is used to change the gameObject's material:
void ChangeTextureViaTerrain(int xx, int yy)
{
float thistile = gM.world[xx + yy * gM.worldWide]; //here
if (thistile == 2f)
{
material = materials[0];
}
else
{
if (thistile > 0.8f)
{
material = materials[2];
}
else
{
material = materials[1];
}
}
}
So, there is an error where it says //here. It says: "ArgumentOutOfRangeException: Argument is out of range. Parameter name: index" However, the list HAS the item that is trying to index. Why it doesn't and gives an error?
Comment
Best Answer
Answer by AlexINF · Dec 25, 2016 at 05:52 PM
Changed float thistile = gM.world[xx + yy * gM.worldWide]
for float thistile = gM.world.BinarySearch(xx + yy * gM.worldWide)
And it works perfectly.
Your answer
Follow this Question
Related Questions
Is it better to store index list or object itself ? 0 Answers
Finding all the same strings in a List 2 Answers
index number problems Forloop 1 Answer
I need help finding the index of an object in a list. 1 Answer
How can i save a list of materials? 0 Answers