프로젝트

일반

사용자정보

통계
| 개정판:

t1 / TFDContents / Assets / KinectScripts / MultiScene / LoadLevelWithDelay.cs @ 3

이력 | 보기 | 이력해설 | 다운로드 (1.37 KB)

1
using UnityEngine;
2
using System.Collections;
3
using UnityEngine.SceneManagement;
4

    
5
public class LoadLevelWithDelay : MonoBehaviour 
6
{
7
	[Tooltip("Seconds to wait before loading next level.")]
8
	public float waitSeconds = 0f;
9

    
10
	[Tooltip("Next level number. No level is loaded, if the number is negative.")]
11
	public int nextLevel = -1;
12

    
13
	[Tooltip("Whether to check for initialized KinectManager or not.")]
14
	public bool validateKinectManager = true;
15

    
16
	[Tooltip("GUI-Text used to display the debug messages.")]
17
	public GUIText debugText;
18

    
19
	private float timeToLoadLevel = 0f;
20
	private bool levelLoaded = false;
21

    
22

    
23
	void Start()
24
	{
25
		timeToLoadLevel = Time.realtimeSinceStartup + waitSeconds;
26

    
27
		if(validateKinectManager && debugText != null)
28
		{
29
			KinectManager manager = KinectManager.Instance;
30

    
31
			if(manager == null || !manager.IsInitialized())
32
			{
33
				debugText.text = "KinectManager is not initialized!";
34
				levelLoaded = true;
35
			}
36
		}
37
	}
38

    
39
	
40
	void Update() 
41
	{
42
		if(!levelLoaded && nextLevel >= 0)
43
		{
44
			if(Time.realtimeSinceStartup >= timeToLoadLevel)
45
			{
46
				levelLoaded = true;
47
				SceneManager.LoadScene(nextLevel);
48
			}
49
			else
50
			{
51
				float timeRest = timeToLoadLevel - Time.realtimeSinceStartup;
52

    
53
				if(debugText != null)
54
				{
55
					debugText.text = string.Format("Time to the next level: {0:F0} s.", timeRest);
56
				}
57
			}
58
		}
59
	}
60
	
61
}