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);
}
}
}
}
}