-
Notifications
You must be signed in to change notification settings - Fork 0
Level Select
Jayden Tarrance edited this page Apr 26, 2024
·
9 revisions

Uses the player's raycast object to click a button, activating the event script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
private void Start()
{
GameObject userMan = GameObject.Find("UserManager");
user = userMan.GetComponent<UserManager>();
if (SceneManager.GetActiveScene().name == "Loading scene")
{
StartCoroutine(LoadSceneAsync(user.nextSceneToLoad));
}
}
public void LoadOfficeAsync()
{
user.nextSceneToLoad = "Office";
SceneManager.LoadScene("Loading scene");
}
public void LoadTutorialAsync()
{
user.nextSceneToLoad = "Tutorial";
SceneManager.LoadScene("Loading scene");
}
public void LoadMainMenuAsync()
{
user.nextSceneToLoad = "Main Menu";
SceneManager.LoadScene("Loading scene");
}
IEnumerator LoadSceneAsync(string sceneName)
{
float startTime = Time.time;
Debug.Log("Loading Scene Async");
// Start loading the scene
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName);
asyncLoad.allowSceneActivation = false;
// While the scene loads, update the slider
while (!asyncLoad.isDone)
{
float elapsedTime = Time.time - startTime;
float remainingTime = loadingDelay - elapsedTime;
//Update slider
float progress = Mathf.Clamp01(remainingTime / loadingDelay);
loadingSlider.value = 1 - progress;
if (remainingTime <= 0)
{
asyncLoad.allowSceneActivation = true; // Allow the next scene to activate
}
yield return null; // Wait a frame before continuing the loop
}
}- Office
Loads the office scene on click. - Traffic Collision
Loads the traffic collision scene on click.