SceneChangeInUnity: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
TomasM (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Fabian (Diskussion | Beiträge) (Änderung 321 von Fabian (Diskussion) rückgängig gemacht.) |
||
(10 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
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 new empty GameObject, name SceneChanger or similar | ||
Zeile 5: | Zeile 5: | ||
* Underneath lays an example of code to change scene after a determined amount of seconds | * Underneath lays an example of code to change scene after a determined amount of seconds | ||
using System.Collections; | |||
using System.Collections.Generic; | |||
using UnityEngine; | using UnityEngine; | ||
Zeile 11: | Zeile 15: | ||
public class ChangeScene : MonoBehaviour | public class ChangeScene : MonoBehaviour | ||
{ | { | ||
public float sceneChangeTime; | public float sceneChangeTime; | ||
public string nextScene; | public string nextScene; | ||
// Start is called before the first frame update | // Start is called before the first frame update | ||
void Start() | void Start() | ||
Zeile 20: | Zeile 24: | ||
StartCoroutine(NextScene()); | StartCoroutine(NextScene()); | ||
} | } | ||
public IEnumerator NextScene() | public IEnumerator NextScene() | ||
{ | { | ||
yield return new WaitForSeconds(sceneChangeTime); | yield return new WaitForSeconds(sceneChangeTime); | ||
SceneManager.LoadScene(nextScene, LoadSceneMode.Single); | 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 | * 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 | * Drag the Next Scene onto the Inspector |
Aktuelle Version vom 22. Oktober 2019, 10:28 Uhr
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 and drag it onto the SceneChanger Game Object
- Underneath lays an example of code to change scene after a determined amount of seconds
using System.Collections;
using System.Collections.Generic;
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