Hello Everyone, I have written this C# code which is my first C# code I have written. I think I have figured it out to a certain point and while it may not be the best way it works up to a point. By the time it gets to the 2nd Scene it stops and I have been unable at all to find a way to make this goto the title. Any Suggestions? This is my code
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
using UnityEngine.UI;
public class SceneManage : MonoBehaviour {
string state;
int tick;
int scenenum;
// Use this for initialization
void Start()
{
StartCoroutine (Wait());
}
void Update(){
if (state == "Ready") {
}
}
IEnumerator Wait(){
yield return new WaitForSeconds (10);
StartCoroutine (Wait2 ());
}
IEnumerator Wait2(){
SceneManager.LoadScene ("SKSLogo", LoadSceneMode.Single);
SceneManager.LoadScene ("Title", LoadSceneMode.Single);
SceneManager.LoadScene ("Title", LoadSceneMode.Single);
}
}
are the three scenes getting loaded? or just the first scene?
why are you creating a second coroutine?
the if statement in the update is doing nothing.
IEnumerator Wait(){
yield return new WaitForSeconds (10); // wait for 10 sec, then do whats under it.
Debug.Log("wait complete");
SceneManager.LoadScene ("SKSLogo", LoadSceneMode.Single);
Debug.Log("SKKLogo loaded");
SceneManager.LoadScene ("Title", LoadSceneMode.Single);
Debug.Log("Title loaded");
SceneManager.LoadScene ("Title", LoadSceneMode.Single); // this is the same as above
}
Hi Johne5, Thank you for your reply. I am trying to load each scene separate wait 10 seconds then load 2nd and finally load the title which another script will take over from there.
mostlikely what you’re after is a don’t destroy on load. and then multiple waits
DontDestroyOnLoad(this.gameObject);
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
using UnityEngine.UI;
public class SceneManage : MonoBehaviour {
private string state; //not being used
private int tick; //not being used
private int scenenum; //not being used
void Awake()
{
DontDestroyOnLoad(this.gameObject);
}
void Start()
{
StartCoroutine (Wait());
}
void Update(){
if (state == "Ready") {
//do something here
}
}
IEnumerator Wait(){
yield return new WaitForSeconds (10); // wait for 10 sec, then do whats under it.
Debug.Log("wait complete");
SceneManager.LoadScene ("SKSLogo", LoadSceneMode.Single);
Debug.Log("SKSLogo loaded");
yield return new WaitForSeconds (10); // wait for 10 sec, then do whats under it.
Debug.Log("wait2 complete");
SceneManager.LoadScene ("Second", LoadSceneMode.Single);
Debug.Log("Second loaded");
yield return new WaitForSeconds (10); // wait for 10 sec, then do whats under it.
Debug.Log("wait3 complete");
SceneManager.LoadScene ("Title", LoadSceneMode.Single);
Debug.Log("Title loaded");
}
}