Question by
fnaveedshah · Jun 12, 2017 at 08:33 AM ·
errorunity5gametanks
IndexOutOfRangeException: tanks index is invalid , i was trying to add new Tank in Tanks!!! game but get this error
//Returns whether a tank for a given index is unlocked.
public bool IsTankUnlocked(int index)
{
if (m_Data.unlockedTanks.Length > index && index >= 0)
{
return m_Data.unlockedTanks[index];
}
return false;
}
//Allows a tank index's unlocked status to be set. Defaults to unlocking the tank.
public void SetTankUnlocked(int index, bool setUnlocked = true)
{
if (m_Data.unlockedTanks.Length > index && index >= 0)
{
m_Data.unlockedTanks[index] = setUnlocked;
}
else
{
throw new IndexOutOfRangeException("Tank index invalid");
}
SaveData();
}
//Returns whether a decoration for a given index is unlocked.
public bool IsDecorationUnlocked(int index)
{
if (m_Data.decorations.Length > index && index >= 0)
{
return m_Data.decorations[index].unlocked;
}
return false;
}
//Allows a decoration index's unlocked status to be set. Defaults to unlocking the decoration.
public void SetDecorationUnlocked(int index, bool setUnlocked = true)
{
if (m_Data.decorations.Length > index && index >= 0)
{
m_Data.decorations[index].unlocked = setUnlocked;
}
else
{
throw new IndexOutOfRangeException("Tank index invalid");
}
SaveData();
}
Comment
Answer by fnaveedshah · Jun 12, 2017 at 08:46 AM
need help guys
if (m_Data.unlockedTanks.Length > index && index >= 0)
{
m_Data.unlockedTanks[index] = setUnlocked;
}
else
{
throw new IndexOutOfRangeException("Tank index invalid");
}
This is where the error occurs, your unlockedTanks length is lower than your index
@shadyproductions ty for rpl sir, i tried increasing length ,decreased as well , but get same error