I want the game to display a prefab (GUIText: "GAME PAUSED") on the center of the screen whenever the game gets paused no matter what the resolution of the game window is. How do I go about doing that?
Below is the script I have written so far:
var bGamePaused : boolean;
var gamePausedPrefab : GameObject;
var gamePausedText : GameObject;
function Update()
{
if(Input.GetKeyUp(KeyCode.P))
{
if(!bGamePaused)
{
Time.timeScale = 0;
gamePausedText = Instantiate(gamePausedPrefab, Vector3(Screen.width / 2, Screen.height / 2, camera.nearClipPlane), Quaternion.identity);
}
else
{
Time.timeScale = 1;
Destroy(gamePausedText);
}
bGamePaused = !bGamePaused;
}
}
This script isn't displaying the prefab anywhere on the screen at the moment. I know that I also have to subtract half the width of my prefab from the x-position and the half the height of my prefab from the y-position, but that's currently the least of my worries as the prefab itself is not being displayed in front of the camera anyway. I know that the code works because the prefab shows up on the lower left corner of the screen when I instantiate the prefab at a position of (0, 0, 0).