Note that there are some explanatory texts on larger screens.

plurals
  1. PODuplicate code but make the copied slower
    primarykey
    data
    text
    <p>I build the shooting game by C# and Unity.</p> <p>I use GameController and GameStatus to show the score and time.</p> <p>At first scene, I have no problem. It can run smoothly.</p> <p>But the second scene, I copy scene from first and make new GameController for second scene.</p> <p>It's work but running game slower.</p> <p>I try to make new project by using same code, but it's slow even it's my first scene.</p> <p>I don't know cause of this happen.</p> <p>Below is my code, it's work.</p> <pre><code>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 &gt;= 300){Application.LoadLevel("MainScene2");} if(countDownTime2 &lt;= 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 &gt; 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 &lt;= 0.0f) { GUI.Label (new Rect(130,50,0,0), "Your Score is " + mScore.ToString(),"scoreStyle2"); } if(menuTime2 &lt;= 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");} } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload