I was making my level select screen for my game when the code that load the corresponded scene didn’t work. It only gives me “ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.”.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class button : MonoBehaviour
{
public int scenetoload;
private bool touched = false;
public void tap()
{
touched = true;
}
public void Update()
{
if (touched)
SceneManager.LoadScene(scenetoload);
}
}
Void Tap() activate with a button click, and sceneToLoad is assigned to 1, All my scenes are in Scenes in Build List ( 18 scenes at total and the level select screen is the first one ). I updated my unity (I was in Version 2019.3.8f1 to 2020.1.9f1) to see if it was a Unity Bug but this error continues. i dont know what to do anymore, what is wrong with my script?
Sorry for any Grammar errors, English is not my principal Language