SceneChangeInUnity
Version vom 23. April 2019, 14:57 Uhr von TomasM (Diskussion | Beiträge)
Here's a quick setup guide on how to use change scenes in Unity 2018.3.x
- Create new empty GameObject, name SceneChanger or similar
- Create a new C ⋕ Script
- Underneath lays an example of code to change scene after a determined amount of seconds:
using UnityEngine; using UnityEngine.SceneManagement;
public class ChangeScene : MonoBehaviour {
public float sceneChangeTime; public string nextScene;
// Start is called before the first frame update
void Start()
{
StartCoroutine(NextScene());
}
public IEnumerator NextScene()
{
yield return new WaitForSeconds(sceneChangeTime);
SceneManager.LoadScene(nextScene, LoadSceneMode.Single);
}
}
- In your Unity Inspector on the Scene Changer Script, determine the amount of seconds that must pass for the scene to change
- Drag the Next Scene onto the Inspector