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 /
avatar image
2
Question by JohannLim · Oct 24, 2012 at 06:20 AM · coroutinetimeboosubtitle

Starting and stopping Coroutines

Hi all,

I'm trying to make a subtitle system where:

  1. text is displayed

  2. for an amount of time

  3. after which, it disappears

  4. OR the player can click to make it disappear

  5. There can be a chain of text

The class for the text and time:

 class SubtitleThread (MonoBehaviour):
     public text as string
     public timer as single = 5.0

The class to manage it:

 class SubtitleSystem (MonoBehaviour): 
     public static showSubtitle as bool = false
     public static subtitleText as string = ""

     def PlaySubtitle (subtitleThreads as (SubtitleThread)) as System.Collections.IEnumerator:
         for eachThread in subtitleThreads:
             yield StartCoroutine("PlaySubtitleCR", eachThread)
             showSubtitle = false
             subtitleText = ""
 
     def PlaySubtitleCR (oneThread as SubtitleThread) as System.Collections.IEnumerator:
         subtitleText = oneThread.text
         showSubtitle = true
         yield WaitForSeconds(oneThread.timer)

     def ClearSubtitle ():
         StopCoroutine("PlaySubtitleCR")
 

Clicking while `showSubtitle == true` will call `ClearSubtitle()`.

However, this does not seem to work. PlaySubtitle will not run when called, and I'm not sure why. When I comment out the "yield" line, it will run - but without the time and "click to continue" functionality.

Any help would be greatly appreciated. Thank you.

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 JohannLim · Oct 24, 2012 at 09:41 AM 0
Share

Thanks very much for the link - good info. I came to realise that I was so hooked on the idea of using Coroutines, I didn't even think of any other way.

I don't see Invoke doing what I want to do. I ended up making a simple timer and putting all the subtitles in a queue, and managing those things ins$$anonymous$$d - which worked beautifully. When the time limit is reached OR when the player clicks, it moves to the next subtitle in the queue; if none, don't show subtitles.

Question now is, how do I close this question without an answer?

avatar image Fattie · Oct 24, 2012 at 11:20 AM 0
Share

i hope it helps in some way, do not hesitate to ask other new questions ! i made an answer , cheers !

1 Reply

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

Answer by Fattie · Oct 24, 2012 at 06:31 AM

there's also StopAllCoroutines()

regarding your code. you shoudl probably learn to use Invoke() first which is incredibly easier

unityGEMS.com for a vast explanation !

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

10 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

Related Questions

Time Manager Class Implementation Like Coroutine in Unity 1 Answer

RPG Action Progress Bar always same speed 1 Answer

Need help developing Damage Over Time mechanic 0 Answers

Timings and synchronization difference after build 0 Answers

(Rapid fire) How to accurately wait for a very short amount of time? 4 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