3 2 1 Go Script Help

Hi, I want to make a script that makes the words “3 2 1 Go!” appear on the screen of the game when I press the play button on Unity. My game so far just starts right off the bat like any normal beta game in Unity. After you press the play button I want the screen to show my game, and then show the 3 2 1 numbers in order one at a time, and then say go! I already started making a script, it doesn’t work so far because it has errors but it’s an early script. All I want is someone to help me fix my script, you can even add things if I missed something. Please help and thank you so much in advance! Oh and I know it’s not the right place to post this, but please understand I’ve been posting too much in the scripting threads already.

public class Go : MonoBehaviour {

	private float initialtime;
	private int restSeconds;
	int CountSeconds;
	int CountMinutes;
	private int seconds;
	private int minutes;
	private string texttime;

	void  Awake (){
		initialtime = Time.time;
		CountSeconds = CountSeconds + (CountMinutes + 60);
	}
	void  OnGUI (){
		guitime = Time.time = initialtime;
		restSeconds = CountSeconds = guitime;
		seconds = restSeconds % 60;
		minutes = restSeconds / 60;
		
		texttime = String.format("(00:0):(00:1)", minutes, seconds);
		
		GetComponent<GUIText>().text = texttime;
		
		if(seconds <= 0 && minutes <= 0)
		{
			//Pause the game
			Time.timeScale = 0;
		}
	}
}

You are getting your GUIs mixed up. Happens commonly enough when you start with Unity.

Unity has several distinct methods of showing text.

UnityGUI

  • This is the method that uses OnGUI(). Typical call is GUI.Label(//Content)
  • This method is best for creating menus and so forth via scripting

To use this method change line 23 of your code to:

GUI.Label(new rect(screen.width/2,screen.height/2,100,100), textTime);

You should probably move the rest of the code into update. OnGUI() can have strange side effects for non GUI code.

GUI objects

  • This is the method that uses GUIText and GUITexture. Calls are typically made during update
  • Best for single objects, like cross hairs or game over text. Or 3…2…1

To use this method move all of your code into Update()

Text Mesh

  • This is more expensive, as the text is an actual 3D object in the world
  • Best when 3D effects are needed, or when text is tied to a specific game location