Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Apr 25, 2014 at 02:59 PM by caleb_b for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by caleb_b · Apr 11, 2014 at 09:34 PM · c#destroypausegui-text

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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lazdena · Apr 11, 2014 at 09:36 PM 0
Share

I think you have to do capital "E" or $$anonymous$$eyCode.$$anonymous$$

avatar image caleb_b · Apr 11, 2014 at 09:45 PM 0
Share

I changed it to

     if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.E)) 

But that didn't change anything. Still doesn't disappear.

2 Replies

  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image caleb_b · Apr 12, 2014 at 12:05 AM 0
Share

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!

avatar image
1

Answer by Ermarrero · Apr 11, 2014 at 09:58 PM

Also put your if statement in Update.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image caleb_b · Apr 11, 2014 at 10:01 PM 0
Share

Duh I should have thought of that. Added the If statement to Update as well, and it works like a charm.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trigger...Spawn...Destroy 1 Answer

Destroy a gameobject from a script on a different game object by tag? 1 Answer

Check if object is destroyed on level load, if so instantiate prefab? 1 Answer

how to instantiate object with content prefab and not him self 2 Answers

Destroying Custom Planes 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges