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 Dec 19, 2014 at 11:05 PM by Bunny83 for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by NivekJump · Dec 19, 2014 at 07:08 PM · coroutineloop

Problem with a Derived Coroutine.

Re Edit: I Solved By Myself, it was just a Variable, thanks to all!

Comment
Add comment · Show 7
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 Bunny83 · Dec 19, 2014 at 08:14 PM 0
Share

Sorry but your strange pseudo code makes no sense at all. Because you don't have a single yield inside the coroutine so your code (even when ignoring the missing syntactical elements) wouldn't compile.

Edit your question and include either your actual code or equivalent code that makes sense.

avatar image NivekJump · Dec 19, 2014 at 08:32 PM 0
Share

Okey i Did it... I knew that my friend, but okey its something like that. Can you help me? The problem is this: the Legacy Coroutine dont do the loop, but it is in the super class. Thanks.

avatar image Kiwasi · Dec 19, 2014 at 08:49 PM 0
Share

What's legacy about this? $$anonymous$$gest checking out the beginner tutorials again.

avatar image NivekJump · Dec 19, 2014 at 09:05 PM 0
Share

This is Legacy because is a Class getting the methods from a super class,

avatar image Kiwasi · Dec 19, 2014 at 09:31 PM 0
Share

That is called derived. Legacy refers to a historical feature that's still supported for backwards compatibility. Like OnGUI, the old animation system, or the old particle system.

Show more comments

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Dec 19, 2014 at 08:48 PM

Sorry but your code is still just garbage. I guess that you use C# however from that strange pseudo code it's hard to tell. If it's C# it would look more like:

 //MainClass.cs
 using UnityEngine;
 using System.Collections;

 public class MainClass : MonoBehaviour
 {
     public IEnumerator MyCoroutine(int var1, int var2)
     {
         while(true)
         {
             for(int i = 0; i < 10; i++)
             {
                 Debug.Log(i);
                 yield return new WaitForSeconds (0.25f);
             }
         }
     }
 }

 //OtherClass.cs
 using UnityEngine;
 using System.Collections;
 
 public class OtherClass : MainClass
 {
     int var1 = 3;
     int var2 = 5;
     void OnMouseDown()
     {
         StartCoroutine(MyCoroutine(var1, var2));
     }
 }

With those classes in your project you can attach OtherClass to an object with a collider and once you clicked on that object you would get a Debug.Log 4 times a second and it would loop forever until you either stop all coroutines or you destroy the object the coroutine runs on.

So this above works, It's based on the sparse information you've provided. I've renamed the method "Coroutine" to "MyCoroutine" as Coroutine is a class name. You should avoid names that are already takesn. If this example doesn't work for you, you must be doing something wrong.

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

Answer by wesleywh · Dec 19, 2014 at 07:54 PM

How do the coroutine know if its true? You will need to specify that.

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 NivekJump · Dec 19, 2014 at 08:18 PM 0
Share

Its always true my friend its an infinite loop, if i wanna stop it, i just do: StopCoroutine(), but i tried your suggestion and it didnt work, i tried this:

 $$anonymous$$ainClass : $$anonymous$$onoBehaviour{
         public IEnumerator Coroutine(var Var1, var Var2, bool value){
           do{
             for(i=0;i<10;i++){
                Debug.log(i);
             }
           }
           while(value)  
        }
      }
 

And when i call it:

 OtherClass : $$anonymous$$ainClass{
           On$$anonymous$$ouseDown(){
           bool value=true;
           StartCoroutine(Coroutine(var1, var2, value));
          }
  }
 

But how i said to you... it didnt work.

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

Coroutine For Loop Will Not End 1 Answer

While loop yield lag? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Slider issue: two sliders are used, but one takes all actions for both. 0 Answers

Sequentially wait for multiple coroutines to finish 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