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
0
Question by azin_psp · May 20, 2015 at 03:52 PM · waitforsecondscoroutines

Call another function during wait for seconds

I have a code like below

StartCoroutine("MyFunction");

function MyFunction() { //Some Line of codes Yield WaitForSeconds(5); //Rest of codes }

But during that WaitForSeconds user may press another button which cause another function call. my problem is that when the other function is called, codes after the WaitForSeconds command do not run. Can anyone help me to know what the problem is? and also the solution!

Comment
Add comment · Show 6
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 DoTA_KAMIKADzE · May 20, 2015 at 01:40 PM 2
Share

Can't help you without "Rest of codes" and "other function code". $$anonymous$$ost likely in your "other function code" you change some value or remove some object which is needed in "Rest of codes". You should revise logic to prevent that (e.g. add some boolean value $$anonymous$$yFunctionLaunched and set it to true before WaitForSeconds, then set it to false after the "Rest of codes" and in your "other function code" check if $$anonymous$$yFunctionLaunched is true before you change that critical data, or something like that). Anyway if you need further assistance provide code.

avatar image spiceboy9994 · May 20, 2015 at 05:00 PM 0
Share

What about creating custom events and subscribe to them, have you tried that? Without code is hard to tell

avatar image azin_psp · May 20, 2015 at 05:59 PM 0
Share

Oh I see in the other function I made deactivate the object which main script is attached to, which cause the script stopped.

Thanks for answering.

avatar image JigneshKoradiya · May 20, 2015 at 06:04 PM 0
Share

plz accept the answer

avatar image JigneshKoradiya · May 20, 2015 at 06:09 PM 0
Share

so we can help you in future if you need help from us next time

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JigneshKoradiya · May 20, 2015 at 05:51 PM

function Start()

{

StartCoroutine("MyFunction");

}

function MyFunction()

{

Yield WaitForSeconds(5); Debug.Log("After 5 second called");

}

function ButtonEvent()

{

StopCoroutine("MyFunction");

Debug.Log("Button Clicked");

}

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

WaitForSeconds not waiting 1 Answer

Coroutines with Yield return new waitforseconds(); go for execution of other functions? 0 Answers

yield, Coroutines, InvokeRepeating... 1 Answer

WaitForSeconds not working in IEnumerator function using MoveNext 1 Answer

How to add a small delay to script? 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