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 /
avatar image
0
Question by Peterwerd · Dec 04, 2016 at 08:25 AM · uitextdialoguestate-machinedialog

How can I create an NPC Dialogue with UI Text?

HI, I already looked around for my problem but didn't find a solution.

Here's what I would like to do. While my character is running in my endless side-scroller game, I would like to tell the player a little story. To do this, I want to use UI Text elements which have animations on them to fade in and out. So on the screen appears a text, e.g., "Hello you." fades out again and then e.g. "Where are you going?" fade out again., and so on, and so on.

Here's my problem now I don't know what would be the right approach to have the sentence fly in on after another. So I tried trigger them with if statements (if (time == 5) say something, if (time == 8) says something else.) But this doesn't seem efficient. Then I tried to do it with an animator and stateMachineBehaviour. That worked a little. Maybe somebody could point me in the right direction?

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 JeffHardddyyy · Dec 04, 2016 at 04:00 PM 0
Share

2d or 3d if I may ask?

avatar image Peterwerd JeffHardddyyy · Dec 05, 2016 at 08:54 AM 0
Share

It is a 3d game. But the dialog is shown with UI Text elements on screen space

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Paricus · Dec 04, 2016 at 04:56 PM

use animations to control the fade in and fade out and create a library of text with an array that gets called every so often.

  public string[] Story;
  int i = 0;
  public Animator anim;
  public float readingTime = 5f;
  public float storyInterval = 10f;

   void Start()
  {
   StartCoroutine(CallText())
  }

   IENumerator CallText()
         {
          anim.setTrigger("ShowTextBox")
          textBox.text = string[i];
          i++;
          yield return new WaitForSeconds(readingTime);
          anim.setTrigger("CloseTextBox")

          yield return new WaitForSeconds(storyInterval)
          StartCoroutine(CallText())
         }





Comment
Add comment · Show 4 · 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 Peterwerd · Dec 05, 2016 at 09:01 AM 0
Share

Thanks. This looks promising. Can you tell me why you are calling StartCoroutine(CallText()) at the end of the IEnumerator CallText()? I haven't really used these before...

avatar image Paricus Peterwerd · Dec 05, 2016 at 09:13 AM 0
Share

Hi, if you're going to program, you'll want to learn how to use coroutines. They're actually very simple to use. They essentially just run code alongside your current scripts.

In c# they allow you to create delays in between line of code, which will eli$$anonymous$$ate the need for a timer. by calling the coroutine at the end of the coroutine, it will repeat the code with the next text in the array.

avatar image Peterwerd Paricus · Dec 05, 2016 at 10:54 PM 0
Share

Hey, thanks again. I just tried it and it works great. I will definitely take a look into coroutines.

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Check current letter in typewriter textbox? 0 Answers

Right approach to prompt a Dialog Box asking for text (equivalent to AlertDialog.Builder and EditText in Android Studio) 0 Answers

Multiple NPCs 1 Answer

Best method for showing text1, then clicking to move onto text2 1 Answer

Last Entry of Dialogue displayed in separate Text (Scriptable objects) 0 Answers


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