You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Jeremy/Assets/Scripts/SceneSwitcher.cs

53 lines
1.1 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SceneSwitcher : MonoBehaviour
{
// make singleton
public static SceneSwitcher Instance { get; private set; }
private void Awake()
{
SetInstance();
}
private void OnValidate()
{
SetInstance();
}
private void SetInstance()
{
if (Instance == null)
{
Instance = this;
}
else
{
Debug.LogError("SceneSwitcher Instance already exists.");
}
}
public void SwitchScene(int sceneIndex)
{
for (var i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).gameObject.SetActive(i == sceneIndex);
}
}
public List<(string name, int index)> GetScenes()
{
var scenes = new List<(string name, int index)>();
for (var i = 0; i < transform.childCount; i++)
{
var child = transform.GetChild(i);
scenes.Add((child.name, i));
}
return scenes;
}
}