using UnityEngine;
using UnityEngine.SceneManagement;
using System.IO;
public class SceneTeleport : MonoBehaviour
{
[SerializeField]
private ProjectScenes openScene;
public void OnInteraction()
{
SceneManager.LoadScene(openScene.ToString());
}
}
public class SceneEnumGenerator : UnityEditor.AssetModificationProcessor
{
private static readonly string stringName = "ProjectScenes";
static string[] OnWillSaveAssets(string[] paths)
{
RewriteSceneEnum();
return paths;
}
private static void RewriteSceneEnum()
{
string path = "Assets/" + stringName + ".cs";
using(StreamWriter streamWriter = new StreamWriter(path))
{
streamWriter.WriteLine("public enum " + stringName);
streamWriter.WriteLine("{");
System.Int32 num = UnityEditor.EditorBuildSettings.scenes.Length;
for(int i = 0; i < num; i++)
{
string name = GetSceneNameFromPath(UnityEditor.EditorBuildSettings.scenes[i].path);
if(i == num - 1)
{
streamWriter.WriteLine(name);
}
else
{
streamWriter.WriteLine(name + ", ");
}
}
streamWriter.WriteLine("}");
}
UnityEditor.AssetDatabase.Refresh();
}
private static string GetSceneNameFromPath(string path)
{
string sceneName = path.Substring(0, path.Length - 6);
return sceneName.Substring(sceneName.LastIndexOf('/') + 1);
}
}
My error is on line nine, where the variable doesn’t recognize the ‘ProjectScenes’, which is created via. StreamWriter below. There are two problems, and I don’t know how to fix them.
1: The script can’t reference ProjectScenes if the variable is created below, and I can’t move it if I wish to keep the script working.
2: The script hasn’t ran yet, therefore meaning that the variable is currently nonexistent.
Any suggestions will help. Thanks!