画面切り替えについては、以下の質問でお答えした通りです。
https://teratail.com/questions/90845
(タイトルが「『シーン』自動遷移」となっているので、後述のソースではSceneManager.LoadScene()
を使ってます)
一定時間経過してから、シーンを切り替える方法は、私が思いつく限りでは以下の2通りが考えられます。
Time.time
で時間を取得し、一定時間経過しているかチェックする方法
C#
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.SceneManagement;
5
6public class SceneChange : MonoBehaviour
7{
8 float startTime;
9
10 void Start()
11 {
12 startTime = Time.time;
13 }
14
15 void Update()
16 {
17 // 5秒経過したか
18 if (Time.time - startTime > 5f)
19 {
20 // シーン切り替え
21 SceneManager.LoadScene("Foo");
22 }
23 }
24}
- コルーチン内で、
WaitForSeconds
を使って一定時間待機する方法
C#
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.SceneManagement;
5
6public class SceneChange : MonoBehaviour
7{
8 IEnumerator Start()
9 {
10 // 5秒待機
11 yield return new WaitForSeconds(5f);
12
13 // シーン切り替え
14 SceneManager.LoadScene("Foo");
15 }
16}
ところで、以下の質問がそのまま放置されておりますが、解決しましたでしょうか?
https://teratail.com/questions/90842
https://teratail.com/questions/90845
もし、解決したのであれば、ベストアンサーをください(ベストアンサーをしていないと、未解決として扱われるためです)。
解決していないのであれば、どこが分からないかをコメント欄で教えてください。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。