- Home /
Problem is not reproducible or outdated
Problem with a Derived Coroutine.
Re Edit: I Solved By Myself, it was just a Variable, thanks to all!
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.
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.
What's legacy about this? $$anonymous$$gest checking out the beginner tutorials again.
This is Legacy because is a Class getting the methods from a super class,
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.
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.
Answer by wesleywh · Dec 19, 2014 at 07:54 PM
How do the coroutine know if its true? You will need to specify that.
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.