1 using UnityEngine;
2 using
System.Collections;
3
4 public
class WelcomeScene : MonoBehaviour {
5
6     
public Texture welcomeBackgroundTexture;
7     
public Texture winBackgroundTexture;
8     
public Texture lossBackgroundTexture;
9
10     
string instruction = "Welcome\n\n" +
11         
"Use arrow keys to move the runner, Space-Bar to jump, C to crouch.\n\n" +
12         
"Use Ctrl + arrow keys to rotate camera.\n\n" +
13         
"Use Plus and Minus keys to move camera forward and backward.\n\n" +
14         
"Use Page-Up, Page-Down, Home and End keys to move camera up, down, left and right.";
15     
string playText = "Play";
16
17     
int buttonHeight = 40;
18     Rect backgroundRect, playRect, playFromStartRect, exitRect;
19
20     
void Start()
21     {
22         
if (!PlayerPrefs.HasKey("Level"))
23         {
24             StartFromBeginning();
25         }
26
27         backgroundRect =
new Rect(Screen.width / 4, Screen.height / 4, Screen.width / 2, Screen.height / 2);
28         playRect =
new Rect(backgroundRect.xMin + 10, backgroundRect.yMax - (buttonHeight + 10), backgroundRect.width / 3, buttonHeight);
29         playFromStartRect =
new Rect(playRect.xMax + 10, playRect.yMin, playRect.width, buttonHeight);
30         exitRect =
new Rect(backgroundRect.xMax - (buttonHeight + 10), playRect.yMin, buttonHeight, buttonHeight);
31     }
32
33     
void OnGUI () {
34         
var gameCompleted = false;
35
36         
if (Game.GameState == GameStates.Win)
37         {
38             GUI.DrawTexture(backgroundRect, winBackgroundTexture);
39             playText =
string.Format("Move to Level {0}", PlayerPrefs.GetInt("Level"));
40
41             gameCompleted = PlayerPrefs.GetInt(
"Level") == Game.EndLevel;
42         }
43         
else if (Game.GameState == GameStates.Loss)
44         {
45             GUI.DrawTexture(backgroundRect, lossBackgroundTexture);
46             playText =
string.Format("Try Level {0} Again", PlayerPrefs.GetInt("Level"));
47         }
48         
else
49         {
50             GUI.DrawTexture(backgroundRect, welcomeBackgroundTexture);
51             
//GUI.Label(new Rect(10, 10, 600, 600), instruction);
52             playText =
string.Format("Play Level {0}", PlayerPrefs.GetInt("Level"));
53
54             gameCompleted = PlayerPrefs.GetInt(
"Level") == Game.EndLevel;
55         }
56
57         
if (!gameCompleted)
58         {
59             
if (GUI.Button(playRect, playText))
60             {
61                 Game.LoadLevel(PlayerPrefs.GetInt(
"Level"));
62             }
63         }
64         
else
65         {
66             GUI.Label(playRect,
"You have completed the game!");
67         }
68
69         
if (GUI.Button(playFromStartRect, "Play From Beginning"))
70         {
71             StartFromBeginning();
72             Game.LoadLevel(PlayerPrefs.GetInt(
"Level"));
73         }
74
75         
if (GUI.Button(exitRect, "Exit"))
76         {
77             Application.Quit();
78         }
79     }
80
81     
void StartFromBeginning()
82     {
83         PlayerPrefs.SetInt(
"Level", 1);
84         PlayerPrefs.SetInt(
"Lives", 5);
85         PlayerPrefs.SetInt(
"Score", 0);
86     }
87 }


Gõ tìm kiếm nhanh...