Index Out of Range Exception - can't figure it out

The error is being thrown up in Start() on Line 2

timeRemaining = timeUntilNextAttack[k];

I can’t figure this one out… the index is 10 floats long, assigned in the inspector.

using System.Collections;

public class GameManager : MonoBehaviour {
    	
	
//Timer Variables
public float[] timeUntilNextAttack;
private float timeRemaining;
public UILabel timerCountdown;
private int days, hours, minutes, seconds, currentAttack;
private string daytext, hourtext, minutetext, secondtext;
public GameObject airEnemies, groundEnemies;
	
//SpawnPoints
public Transform[] northGroundSpawns, eastGroundSpawns, westGroundSpawns, southGroundSpawns;
public Transform[] northAirSpawns, eastAirSpawns, westAirSpawns, southAirSpawns;
public Transform[] caveSpawns;
	
//Attack Wave Specific Variables	
public int[] attack1WaveNumber;
public int[] attack1EnemyNumber;
public GameObject[] attack1EnemyType;
public string[] attack1EnemyDirection;
public int[] attack1EnemyLevel;

    										
	//begins initial timer at start of game. 
	//Subsequent timers set at end of attack 

public void Start(){

		int k = 0;
		timeRemaining = timeUntilNextAttack[k];
		
		SetAttackTimer();
		
	}
	
	//starts timer
	public void SetAttackTimer(){
		
		
	
		InvokeRepeating ("Countdown", 1.0f, 1.0f);	
	
	}	
	
	//actual timer and relay of information to in-game text displaying timer
	public void Countdown(){
		Debug.Log (timeRemaining+" second remaining");
		timeRemaining -= 1f;
		days    = Mathf.FloorToInt(timeRemaining / 86400F); 
		hours   = Mathf.FloorToInt((timeRemaining - (days*86400)) / 3600F); 
		minutes = Mathf.FloorToInt((timeRemaining - (days*86400)-(hours*3600)) / 60F);
   		seconds = Mathf.FloorToInt(timeRemaining - (days*86400)-(hours*3600)-(minutes*60));
 		
		if(days > 1)daytext = " days, ";
		else if(days == 1)daytext = " day, ";
		else if(days < 1){
			days = 0;
			daytext = "";
			}
		if(hours > 1)hourtext = " hours, ";
		else if(hours == 1)hourtext = " hour, ";
		else if(hours < 1){
			if(days < 1){
				hours = 0;
				hourtext = " ";
				}
			else{
				hourtext = " hours, ";
				}
			}
		if(minutes > 1)minutetext = " mins, ";
		else if(minutes == 1)minutetext = " min, ";
		else if(minutes < 1){
			if(hours < 1 || days < 1){
				minutes = 0;
				minutetext = " ";
				}
			else{
				minutetext = " mins, ";
				}
			}
		if(seconds > 1)secondtext = " secs";
		else if(seconds == 1)secondtext = " sec";
		else if(seconds < 1){
			if(hours < 1 || days < 1 || minutes < 1){
				seconds = 0;
				secondtext = " ";
				}
			else{
				secondtext = " secs";
				}
			}
		timerCountdown.text = days+daytext+hours+hourtext+minutes+minutetext+seconds+secondtext;
		
		//timer is up, start the attack and cancel the timer
		if(timeRemaining <=0){
			StartAttack();
			CancelInvoke("Countdown");
			 }
	}

	//initiates the oncoming attack
	public void StartAttack(){
	Debug.Log ("Start Attack!");	
	if(currentAttack == 0)Attack1();	
	}
	
	//Attack # 1
	public void Attack1(){
			
		
	//find max wave number and replace timer with wave of wave count
	int maxWave = 0;
	for (int i = 0; i < attack1WaveNumber.Length; i++)
		{
			if (attack1WaveNumber *> maxWave)*
  •  {*
    

_ maxWave = attack1WaveNumber*; _
_
}}_
_
timerCountdown.text = “Wave 1 of “+maxWave;_
_
Debug.Log (maxWave+” Is the max wave”);*_

* //for each wave # in Attack#Wave Number…instantiate guys from other arrays *
* for (int j = 0; j < attack1WaveNumber.Length; j++)*
* {*

* if (attack1WaveNumber[j] == 1)*
* {*

* if(attack1EnemyDirection[j] == “north”){*

* if(attack1EnemyType[j].tag == “groundenemy”)*
* { int spawnChoice = Random.Range(0,northGroundSpawns.Length);*

* //spawn number of enemy above at place above*
* int numberToSpawn = attack1EnemyNumber[j];*
* for (int k = 0; k < numberToSpawn; k++) {*
* GameObject newEnemy = Instantiate(attack1EnemyType[j], northGroundSpawns[spawnChoice].position, northGroundSpawns[spawnChoice].rotation) as GameObject;*
* Debug.Log (newEnemy.name);*
* newEnemy.GetComponent().unitLevel = attack1EnemyLevel[j];*
* newEnemy.transform.parent = groundEnemies.transform;*
* }*
* }*
* else if(attack1EnemyType[j].tag == “airenemy”)*
* { int spawnChoice = Random.Range(0,northAirSpawns.Length);*

* //spawn number of enemy above at place above*
* int numberToSpawn = attack1EnemyNumber[j];*
* for (int k = 0; k < numberToSpawn; k++) {*
* GameObject newEnemy = Instantiate(attack1EnemyType[j], northAirSpawns[spawnChoice].position, northAirSpawns[spawnChoice].rotation) as GameObject;*
* Debug.Log (newEnemy.name);*
* newEnemy.GetComponent().unitLevel = attack1EnemyLevel[j];*
* newEnemy.transform.parent = airEnemies.transform;*
* }*
* }*
* }*
* else if(attack1EnemyDirection[j] == “east”){*

* if(attack1EnemyType[j].tag == “groundenemy”)*
* { int spawnChoice = Random.Range(0,eastGroundSpawns.Length);*

* //spawn number of enemy above at place above*
* int numberToSpawn = attack1EnemyNumber[j];*
* for (int k = 0; k < numberToSpawn; k++) {*
* GameObject newEnemy = Instantiate(attack1EnemyType[j], eastGroundSpawns[spawnChoice].position, eastGroundSpawns[spawnChoice].rotation) as GameObject;*
* Debug.Log (newEnemy.name);*
* newEnemy.GetComponent().unitLevel = attack1EnemyLevel[j];*
* newEnemy.transform.parent = groundEnemies.transform;*
* }*
* }*
* else if(attack1EnemyType[j].tag == “airenemy”)*
* { int spawnChoice = Random.Range(0,eastAirSpawns.Length);*

* //spawn number of enemy above at place above*
* int numberToSpawn = attack1EnemyNumber[j];*
* for (int k = 0; k < numberToSpawn; k++) {*
* GameObject newEnemy = Instantiate(attack1EnemyType[j], eastAirSpawns[spawnChoice].position, eastAirSpawns[spawnChoice].rotation) as GameObject;*
* Debug.Log (newEnemy.name);*
* newEnemy.GetComponent().unitLevel = attack1EnemyLevel[j];*
* newEnemy.transform.parent = airEnemies.transform;*
* }*
* }*
* }*
* if(attack1EnemyDirection[j] == “west”){*

* if(attack1EnemyType[j].tag == “groundenemy”)*
* { int spawnChoice = Random.Range(0,westGroundSpawns.Length);*

* //spawn number of enemy above at place above*
* int numberToSpawn = attack1EnemyNumber[j];*
* for (int k = 0; k < numberToSpawn; k++) {*
* GameObject newEnemy = Instantiate(attack1EnemyType[j], westGroundSpawns[spawnChoice].position, westGroundSpawns[spawnChoice].rotation) as GameObject;*
* Debug.Log (newEnemy.name);*
* newEnemy.GetComponent().unitLevel = attack1EnemyLevel[j];*
* newEnemy.transform.parent = groundEnemies.transform;*
* }*
* }*
* else if(attack1EnemyType[j].tag == “airenemy”)*
* { int spawnChoice = Random.Range(0,westAirSpawns.Length);*

* //spawn number of enemy above at place above*
* int numberToSpawn = attack1EnemyNumber[j];*
* for (int k = 0; k < numberToSpawn; k++) {*
* GameObject newEnemy = Instantiate(attack1EnemyType[j], westAirSpawns[spawnChoice].position, westAirSpawns[spawnChoice].rotation) as GameObject;*
* Debug.Log (newEnemy.name);*
* newEnemy.GetComponent().unitLevel = attack1EnemyLevel[j];*
* newEnemy.transform.parent = airEnemies.transform;*
* }*
* }*
* }*
* if(attack1EnemyDirection[j] == “south”){*

* if(attack1EnemyType[j].tag == “groundenemy”)*
* { int spawnChoice = Random.Range(0,southGroundSpawns.Length);*

* //spawn number of enemy above at place above*
* int numberToSpawn = attack1EnemyNumber[j];*
* for (int k = 0; k < numberToSpawn; k++) {*
* GameObject newEnemy = Instantiate(attack1EnemyType[j], southGroundSpawns[spawnChoice].position, southGroundSpawns[spawnChoice].rotation) as GameObject;*
* Debug.Log (newEnemy.name);*
* newEnemy.GetComponent().unitLevel = attack1EnemyLevel[j];*
* newEnemy.transform.parent = groundEnemies.transform;*
* }*
* }*
* else if(attack1EnemyType[j].tag == “airenemy”)*
* { int spawnChoice = Random.Range(0,southAirSpawns.Length);*

* //spawn number of enemy above at place above*
* int numberToSpawn = attack1EnemyNumber[j];*
* for (int k = 0; k < numberToSpawn; k++) {*
* GameObject newEnemy = Instantiate(attack1EnemyType[j], southAirSpawns[spawnChoice].position, southAirSpawns[spawnChoice].rotation) as GameObject;*
* Debug.Log (newEnemy.name);*
* newEnemy.GetComponent().unitLevel = attack1EnemyLevel[j];*
* newEnemy.transform.parent = airEnemies.transform;*
* }*
* }*
* }*

* }*
* }*

* }*

* public void AttackWin(){*

* //setup next timer*
* currentAttack += 1;*
* int i = currentAttack;*
_ //timeRemaining = timeUntilNextAttack*;
SetAttackTimer();*_

* }*

}

Are you filling in the values of timeUntilNextattack in the inspector? You could fill your array in Start() like so for testing:

timeUntilNextAttack = new float[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1};