예제 #1
0
파일: UserGUI.cs 프로젝트: disschen/Unity3D
    void OnGUI()
    {
        bold_style.normal.textColor  = new Color(1, 0, 0);
        bold_style.fontSize          = 16;
        text_style.normal.textColor  = new Color(0, 0, 0, 1);
        text_style.fontSize          = 16;
        score_style.normal.textColor = new Color(1, 0, 1, 1);
        score_style.fontSize         = 16;
        over_style.normal.textColor  = new Color(1, 0, 0);
        over_style.fontSize          = 25;

        if (!game_start)
        {
            GUI.Label(new Rect(Screen.width / 2 - 30, Screen.width / 2 - 350, 100, 100), "HelloUFO!", over_style);
            GUI.Label(new Rect(Screen.width / 2 - 150, Screen.width / 2 - 220, 400, 100), "大量UFO出现,点击它们,即可消灭,快来加入战斗吧", text_style);
            if (GUI.Button(new Rect(Screen.width / 2 - 20, Screen.width / 2 - 150, 100, 50), "游戏开始"))
            {
                Debug.Log(game_start);
                game_start = true;
                action.BeginGame();
            }
        }
        else
        {
            //用户射击
            if (Input.GetButtonDown("Fire1"))
            {
                Vector3 pos = Input.mousePosition;
                Debug.Log("right here userGUI 1");
                action.Hit(pos);
            }

            GUI.Label(new Rect(10, 5, 200, 50), "分数:", text_style);
            GUI.Label(new Rect(55, 5, 200, 50), action.GetScore().ToString(), score_style);

            GUI.Label(new Rect(Screen.width - 120, 5, 50, 50), "生命:", text_style);
            //显示当前血量
            for (int i = 0; i < life; i++)
            {
                GUI.Label(new Rect(Screen.width - 75 + 10 * i, 5, 50, 50), "X", bold_style);
            }
            //游戏结束
            if (life == 0)
            {
                high_score = high_score > action.GetScore() ? high_score : action.GetScore();
                GUI.Label(new Rect(Screen.width / 2 - 20, Screen.width / 2 - 250, 100, 100), "游戏结束", over_style);
                GUI.Label(new Rect(Screen.width / 2 - 10, Screen.width / 2 - 200, 50, 50), "最高分:", text_style);
                GUI.Label(new Rect(Screen.width / 2 + 50, Screen.width / 2 - 200, 50, 50), high_score.ToString(), text_style);
                if (GUI.Button(new Rect(Screen.width / 2 - 20, Screen.width / 2 - 150, 100, 50), "重新开始"))
                {
                    life = 6;
                    action.ReStart();
                    return;
                }
                action.GameOver();
            }
        }
    }
예제 #2
0
 private void OnGUI()
 {
     if (!ss)
     {
         S = Time.time;
     }
     GUI.Label(new Rect(1000, 50, 500, 500), "Score: " + UserActionController.GetScore().ToString() + "  Time:  " + ((int)(Time.time - S)).ToString() + "  Round:  " + round);
     if (!ss && GUI.Button(new Rect(Screen.width / 2 - 30, Screen.height / 2 - 30, 100, 50), "Start"))
     {
         S  = Time.time;
         ss = true;
         UserActionController.Restart();
     }
     if (ss)
     {
         round = UserActionController.GetRound();
         if (Input.GetButtonDown("Fire1"))
         {
             Vector3 pos = Input.mousePosition;
             UserActionController.Hit(pos);
         }
         if (round > 3)
         {
             round = 3;
             if (UserActionController.RoundStop())
             {
                 ss = false;
             }
         }
     }
 }
예제 #3
0
 void Update()
 {
     if (!ss)
     {
         S = Time.time;
     }
     btnStart.SetActive(!ss);
     text.text = "Score: " + UserActionController.GetScore().ToString() + "  Time:  " + ((int)(Time.time - S)).ToString() + "  Round:  " + round;
     if (ss)
     {
         round = UserActionController.GetRound();
         if (Input.GetButtonDown("Fire1"))
         {
             Vector3 pos = Input.mousePosition;
             UserActionController.Hit(pos);
         }
         if (round > 3)
         {
             round = 3;
             if (UserActionController.RoundStop())
             {
                 ss = false;
             }
         }
     }
 }
예제 #4
0
 private void OnGUI()
 {
     if (!ss)
     {
         S = Time.time;
     }
     GUI.Label(new Rect(Screen.width - 160, 30, 150, 30), "Score: " + UserActionController.GetScore().ToString() + "  Time:  " + ((int)(Time.time - S)).ToString());
     if (ss)
     {
         if (!UserActionController.GetGameState())
         {
             ss = false;
         }
     }
     else
     {
         if (GUI.Button(new Rect(Screen.width / 2 - 30, Screen.height / 2 - 30, 100, 50), "Start"))
         {
             ss = true;
             SceneController.LoadResources();
             S = Time.time;
             UserActionController.Restart();
         }
     }
 }
예제 #5
0
    private void OnGUI()
    {
        if (userAction.GetScore() > maxScore)
        {
            maxScore = userAction.GetScore();
        }
        if (!isPlaying)
        {
            S = Time.time;
        }
        //分数、时间、回合
        string text = "分数: " + userAction.GetScore().ToString() + "  时间:  " + ((int)(Time.time - S)).ToString() + "  回合:  " + round;

        GUI.Label(new Rect(10, 10, Screen.width, 50), text);

        if (!isPlaying && GUI.Button(new Rect(Screen.width / 2 - 75, Screen.height / 2 - 25, 150, 50), "开始游戏"))
        {
            S         = Time.time;
            isPlaying = true;
            userAction.Restart();   //点击开始游戏,FirstSceneController开始游戏
        }
        if (isPlaying)
        {
            round = userAction.GetRound();
            if (Input.GetButtonDown("Fire1"))
            {
                //把鼠标点击的位置传给FirstScenceController,处理点击事件
                Vector3 pos = Input.mousePosition;
                userAction.Hit(pos);
            }
            if (round > 3)  //round>3要等待飞碟都用完了
            {
                round = 3;
                if (userAction.RoundStop())
                {
                    isPlaying = false;
                }
            }
        }
    }
예제 #6
0
 private void OnGUI()
 {
     if (start)
     {
         lastTime = ((int)(Time.time - startTime));
         GUI.Label(new Rect(50, 30, 200, 30), "Score: " + (userAction.GetScore() / 4).ToString() + "  Time: " + lastTime.ToString());
         if (!userAction.GetGameState())
         {
             start = false;
         }
     }
     else
     {
         GUI.Label(new Rect(50, 30, 200, 30), "Score: " + (userAction.GetScore() / 4).ToString() + "  Time: " + lastTime.ToString());
         if (GUI.Button(new Rect(Screen.width / 2 - 30, Screen.height / 2 - 30, 100, 50), "Start"))
         {
             start = true;
             userAction.Restart();
             startTime = Time.time;
         }
     }
 }
예제 #7
0
    private void OnGUI()
    {
        if (!ss)
        {
            S = Time.time;
        }
        GUI.Label(new Rect(0, 30, 75, 30), "Crystal: " + SceneController.GetCollector().ToString());
        GUI.Label(new Rect(Screen.width - 160, 30, 150, 30), "Score: " + UserActionController.GetScore().ToString() + "  Time:  " + ((int)(Time.time - S)).ToString());
        if (ss)
        {
            if (!UserActionController.GetGameState())
            {
                ss = false;
            }
            if (SceneController.GetCollector() >= 9)
            {
                win = true;
                ss  = false;
            }
        }
        else
        {
            if (win)
            {
                GUIStyle fontStyle = new GUIStyle();
                fontStyle.alignment        = TextAnchor.MiddleCenter;
                fontStyle.fontSize         = 25;
                fontStyle.normal.textColor = Color.white;
                GUI.Label(new Rect(Screen.width / 2 - 25, Screen.height / 2 - 80, 100, 50), "WINNER!", fontStyle);
                PF = PropFactory.PF;
                PF.StopPatrol();

                if (GUI.Button(new Rect(Screen.width / 2 - 30, Screen.height / 2 - 30, 100, 50), "EXIT"))
                {
                    UnityEditor.EditorApplication.isPlaying = false;
                }
            }

            else if (GUI.Button(new Rect(Screen.width / 2 - 30, Screen.height / 2 - 30, 100, 50), "Start"))
            {
                ss = true;
                SceneController.LoadResources();
                S = Time.time;
                UserActionController.Restart();
            }
        }
    }
예제 #8
0
    private void OnGUI()
    {
        if (!ss)
        {
            S = Time.time;
        }

        if (!ss && GUI.Button(new Rect(Screen.width / 2 - 30, Screen.height / 2 - 30, 100, 50), "Start"))
        {
            S  = Time.time;
            ss = true;
            UserActionController.Restart();
            controller.LoadResources();
        }
        if (ss)
        {
            GUI.Button(new Rect(0, 0, 100, 50), "Round: " + round);
            GUI.Button(new Rect(0, 55, 100, 50), "Score: " + UserActionController.GetScore().ToString());
            GUI.Button(new Rect(0, 110, 100, 50), "Time: " + ((int)(Time.time - S)).ToString());
            if (GUI.Button(new Rect(0, 165, 100, 50), "Reset"))
            {
                S = Time.time;
                UserActionController.Restart();
            }
            round = UserActionController.GetRound();
            if (Input.GetButtonDown("Fire1"))
            {
                Vector3 pos = Input.mousePosition;
                UserActionController.Hit(pos);
            }
            if (round > 10)
            {
                round = 10;
                if (UserActionController.RoundStop())
                {
                    ss = false;
                }
            }
        }
    }
예제 #9
0
파일: UserGUI.cs 프로젝트: disschen/Unity3D
    // Update is called once per frame
    void OnGUI()
    {
        bold_style.normal.textColor  = new Color(1, 0, 0);
        bold_style.fontSize          = 16;
        text_style.normal.textColor  = new Color(0, 0, 0, 1);
        text_style.fontSize          = 16;
        score_style.normal.textColor = new Color(1, 0, 1, 1);
        score_style.fontSize         = 16;
        over_style.normal.textColor  = new Color(1, 0, 0);
        over_style.fontSize          = 25;

        if (!game_start)
        {
            GUI.Label(new Rect(Screen.width / 2 - 200, Screen.height / 2 - 320, 400, 100), "你的孩子被乌鸦抓走了!快去拯救它吧!", text_style);
            if (GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 250, 100, 50), "游戏开始"))
            {
                Debug.Log(game_start);
                game_start = true;
                action.BeginGame();
            }
        }
        else
        {
            GUI.Label(new Rect(10, 5, 200, 50), "分数:", text_style);
            GUI.Label(new Rect(55, 5, 200, 50), action.GetScore().ToString(), score_style);

            //游戏结束
            if (action.IfGameOver())
            {
                GUI.Label(new Rect(Screen.width / 2 - 20, Screen.width / 2 - 250, 100, 100), "游戏结束", over_style);
                if (GUI.Button(new Rect(Screen.width / 2 - 20, Screen.width / 2 - 150, 100, 50), "重新开始"))
                {
                    action.ReStart();
                    return;
                }
                action.GameOver();
            }
        }
    }