0

我用 C# 和 Unity 构建了射击游戏。

我使用 GameController 和 GameStatus 来显示分数和时间。

在第一个场景中,我没有问题。它可以顺利运行。

但是第二个场景,我从第一个场景复制并为第二个场景制作新的 GameController。

它的工作,但运行游戏速度较慢。

我尝试使用相同的代码制作新项目,但即使这是我的第一个场景,它也很慢。

我不知道发生这种情况的原因。

下面是我的代码,它的工作。

using UnityEngine;
using System.Collections;

public class MyGameController2 : MonoBehaviour 

    private Gun gun;

    public GUISkin mySkin2;

    private GameStatus gameStatus;

    public float countDownTime2;
    private float scoreTime2;
    private float menuTime2;
    // Use this for initialization
    void Start () {
        countDownTime2 = 60.0f;
        scoreTime2 = countDownTime2+3;
        menuTime2 = countDownTime2+5;
        gameStatus = (GameStatus)GetComponent(typeof(GameStatus));
    }
        // Update is called once per frame
    void Update () {
        countDownTime2 -= Time.deltaTime;
        if(gameStatus.score >= 300){Application.LoadLevel("MainScene2");}
        if(countDownTime2 <= 0.0f)
        {gameStatus.isGameOver = true;
        countDownTime2 = 0.0f;
        gameStatus.score +=0;
        }
        scoreTime2 -= Time.deltaTime;
        menuTime2 -= Time.deltaTime;


    }

    void OnGUI() 
    {
        float sw = Screen.width;
        float sh = Screen.height;
        GUI.skin = mySkin2;
        int mScore = gameStatus.score;
        if(countDownTime2 > 0.0f){
        GUI.Label (new Rect(50,0,sw/2,sh/2), "Score : " + mScore.ToString(),"scoreStyle");
        GUI.Label (new Rect(400,0,0,0), "Time : " + countDownTime2.ToString("000") ,"timeStyle");
        }
        if(gameStatus.isGameOver)
        {GUI.Label (new Rect(120,100,sw/2,sh/4),"Game Over","messageStyle");}

        if (scoreTime2 <= 0.0f)
        {
        GUI.Label (new Rect(130,50,0,0), "Your Score is " + mScore.ToString(),"scoreStyle2");   
        }

        if(menuTime2 <= 0.0f){
        // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
        if(GUI.Button(new Rect(100,220,80,20), "Retry")) {
            Application.LoadLevel("MainScene");}

        if(GUI.Button(new Rect(300,220,80,20), "Menu")) {
            Application.LoadLevel("TitleScene");}
        }
    }
}
4

0 回答 0