- Home /
The question is answered, right answer was accepted
Create a text box that appears at start of game, then disappears with any player input
I want to make a text box that appears when the game is started, containing gameplay instructions, then disappears when the player presses any button. Also, the game needs to not begin until the window has been closed. Here is what I've got so far:
I have created a GUIText, with a script attached to it called TextController.cs Here is the script
using UnityEngine;
using System.Collections;
public class TextController : MonoBehaviour
{
public GUIText instructionsText;
// Use this for initialization
void Start ()
{
instructionsText.text = "Your mission: Protect the Interplanetary Space Station." +
"WASD to move, left Control to fire.";
if (Input.GetKeyDown("e"))
{
Destroy(gameObject);
}
}
// Update is called once per frame
void Update () {
}
}
When I play the game, the text is there, but is not destroyed when the E key is pressed. Also, the game plays automatically, as I don't know how to tell it not to. Note that the E key thing is just a quick solution. I'd like it do be destroyed when there is any input at all. So the questions are : how do I destroy, or otherwise deactivate the text when the player presses a button, and how do I pause the game until the player has closed the window?
I think you have to do capital "E" or $$anonymous$$eyCode.$$anonymous$$
I changed it to
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.E))
But that didn't change anything. Still doesn't disappear.
Answer by Paulo-Henrique025 · Apr 11, 2014 at 10:03 PM
You can try this:
void Start()
{
instructionsText.text = "Your text";
Time.timeScale = 0;
}
void Update ()
{
if(Input.anyKeyDown)
{
Time.timeScale = 1;
Destroy(gameObject);
}
}
This way the game only starts when you press the key.
Your code is not working because you are checking for Inputs just once in the start. You have to check for inputs during game, and not once, that is why we have the update function, as soon as it is finished it is called again and again.
Great that did it perfectly! $$anonymous$$arking best answer :) There are other projects that I am working on that could use the Time.timesclae stuff as well, so you just taught me something very useful. Thanks again!
Answer by Ermarrero · Apr 11, 2014 at 09:58 PM
Also put your if statement in Update.
Duh I should have thought of that. Added the If statement to Update as well, and it works like a charm.