Pretty simple code, really don’t understand why I can’t reassign arrays in these circumstances (error CS0165: Use of unassigned local variable `trapToChoose’):
int[] trapToChoose;
switch (gameManagerScript.landscape)
{
case "City":
if (floorNumber < 51)
{
trapToChoose = new int[] {20, 50, 70, 100, 100, 100};
}
else if (floorNumber > 50 && floorNumber < 101)
{
trapToChoose = new int[] {20, 50, 70, 100, 100, 100};
}
else if (floorNumber > 100)
{
trapToChoose = new int[] {20, 50, 70, 100, 100, 100};
}
break;
case "Forest":
if (floorNumber < 51)
{
trapToChoose = new int[] {20, 50, 70, 100, 100, 100};
}
else if (floorNumber > 50 && floorNumber < 101)
{
trapToChoose = new int[] {20, 50, 70, 100, 100, 100};
}
else if (floorNumber > 100)
{
trapToChoose = new int[] {20, 50, 70, 100, 100, 100};
}
break;
default:
print (" PopTrap Script Error");
trapToChoose = new int[] {0, 0, 0, 0, 0, 0};
break;
}
randomPicker = (int) Mathf.Round(Random.Range(0, 100));
if (randomPicker <= trapToChoose[0])
chosenTrap = 0;
else if (randomPicker > trapToChoose[0] && randomPicker <= trapToChoose[1])
chosenTrap = 1;
Also, would love to know why I am forced to use the {} for the If statement inside a switch (embedded statement error)