I’ve 70 scenes and want the player to be able to search the name of scene through a search menu. I’ve been ‘searching’ for any clues to do this but to no avail?
Unity doesn’t directly seem to have a code function to return all the scenes, so here’s how i would do it:
- create a string array with 70 slots, and in each slot assign the name of a scene. (lots of busy work here)
- Using a Unity UI Input Field as your input source, loop through the array (in update or after a submit query to ease performance) and return all of the strings that contain the input text in it.
- create UI icons corresponding to each level, and make a way to identify which icons to show based on the list returned from the loop in step 2. There is likely a more efficient but more code induced way to do this than hard coding, but this works as a running start.
- now in each ui icon, when its clicked, just run a scenemanager.loadscene(string scene); script to execute the level loading.
Best of luck, this should be a good starting point for you
Hello @tommystyhlz,
Here is some guess code for you. This might help you for your search bar functioning. I havnt tested it but i think this gonna helpful for you.
public List<string> levelNames;
string checkNames;
public void SearchMenuFunction()
{
for (int i = 0; i < levelNames.Count; i++)
{
if (levelNames*.name.StartsWith(checkNames))*
{
//You can write your functioning here where you can load by using .
//Use unity UI function for this.
//When you start typing then in Input Field you will see levels names
print(checkNames);
}
else if (!levelNames*.name.StartsWith(checkNames))*
{
//Here you can sort out name which are not relevant to typing text.
}
}
}