Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by MrWhiteSwitch · Nov 07, 2015 at 03:40 AM · textdelayunity 4.6

How to display text with delay (No GUI code in script)

Hi !

I am really new to coding in Unity, and I'm trying to make a text appear after 3 seconds, but the GUI Text Box is in my Unity 2D scene and not in the script. Here is my Code, It's actually way bigger than this but this is basically what you guys should need to help me. Thanks !

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class NewBehaviourScript : MonoBehaviour {
     public AudioClip cenasound;
     public Text text;
     
     private enum States 
     {forest,forest_v, bushes_0, treetrunk_0, birdnest_0, snail, snail_v,
     birdnest_1, bushes_1, treetrunk_1,
     lightbulb_1, lightbulb_0,
     cabinfound_1, cabinfound_0,
     inCabin_bulb, inCabin_nobulb,};
     
     private States myState;
     
     // Use this for initialization
     void Start () {
         myState = States.forest;
     }
    void Update () {
            if (myState == States.cabinfound_0) {cabinfound_0();}
     }
 void cabinfound_0 () {
             text.text = "blahblah";
 }
 void lightbulb_0() {
         text.text = "\n\n\t\t\t\t\t\tThis action will have consequences...\n\n\n Press the spacebar to continue.";
         if (Input.GetKeyDown(KeyCode.Space)) {myState = States.cabinfound_0;}    
     }

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Cepheid · Nov 07, 2015 at 09:49 PM

Hi there! @MrWhiteSwitch I assume you're using the new 4.6 Unity GUI? If so then there are a couple of quick ways of doing this by simply using the Invoke method. (If I've understood the question correctly).

The first will require a GameObject reference for your text component which we can then activate and deactivate as shown below:

     public GameObject textBox;
 
     void Start ()
     {
         textBox.SetActive(false);
 
         Invoke(DisplayText, 3f);
     }
 
     void DisplayText ()
     {
         textBox.SetActive(true);
     }

However if all that you have on screen is a text box and no background image as child. Then the other way of doing this would be to simply start the text with an empty string value and then simply assign the string you wish it to display after 3 seconds like so:

     void Start ()
     {
         text.text = "";
         Invoke(DisplayText, 3f);
     }
 
     void DisplayText ()
     {
         text.text = "I am now display text.";
     }

Now I'm sure you don't want to the delay to begin in Start but you can place the Invoke method wherever you want and it will wait for 3 or however many seconds you want it to before executing the DisplayText method. I hope this helps! If I've completely misunderstood you though and given you a pointless answer please feel free to correct me so that I can possibly give you a more suited answer.

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

33 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[Help] how do I reference/access another script in unity C# 2 Answers

My 'Score' Variable Is Not Printing To UI Text 1 Answer

Hide (not delete) text after given time..? 1 Answer

Can not properly display the score on pong game 0 Answers

What are the steps for the player to be able to create a list of items, then have the computer select and show a single item from that list? 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