Index out of bounds error. I have this error stacking for each of this script in the scene. How do i fix it?

Hi guys. Im new to unity and i am trying to make a simple game. I made this script for my menu and to go back to the menu from the game. However it keeps spamming the console with errors once i run the game. The script itself works fine otherwise. Is there a way to get rid of the errors?

This is the error that i keep getting:

UnityException: Index out of bounds.

NextScene.loadNext () (at Assets/Scripts/NextScene.cs:21)

NextScene.Update () (at Assets/Scripts/NextScene.cs:11)

using UnityEngine;
using System.Collections;

public class NextScene : MonoBehaviour 
{
	public int loadThisScene;

	void Update()
	{
		loadNext ();
	}

	void loadNext()
	{
	RaycastHit hitInfo;
	Touch touch =Input.GetTouch(0);
	Ray ray = Camera.main.ScreenPointToRay(touch.position);
	if(Input.touchCount > 0 && touch.phase == TouchPhase.Began)
	{
	if (collider.Raycast (ray,out hitInfo, 10e8f))
	{
	if(!Physics.Raycast (ray, hitInfo.distance - 0.01f))
	{
	Application.LoadLevel(loadThisScene);
	}
}
}
}
}

The reason is that you have not assigned a value to your ‘loadThisScene’ variable. And Application.LoadLevel() requires either an integer or string argument.

Even though you are passing a variable that is integer there is no actual value assigned to that variable, hence the error.

Assign the index of scene you want to load to ‘loadThisScene’ variable and you’re good to go.

Is it possible that you removed some code from this script? The error should be in line 16 where you use the index 0 with the GetTouch method without checking if there is any touch.