- Home /
IEnumerator is not called
I try to call my IEnumerator function, but for some reason it does not respond.
Here's the code and the console messages:
public class Swing_Movement : SlideSwing_Basic
{
//Variables
void Start()
{
StartCoroutine(MovementController()); //Note: there are 7 objects with this script
}
void manipulate()
{
if (Input.GetButtonDown("Manipulate Object") && !BlockInput)
{
Invoke("MovementController", 0.0f);
print("MovementController call");
}
}
IEnumerator MovementController()
{
print("MovementController respond");
//Do stuff
}
}
There are 7 objects with this script, so after the "MovementController call" there should be 8 "MovementController respond" messages!

Well I tried to use it and ... Well it doenst work for me neither. Invoke doesnt call my IEnumerator, but you can do the very same thing, by calling the IEnumerator with "StartCoroutine();" and then make the first line in IEnumerator "yield return new WaitForSeconds(blaTime);"
The IEnumerator could have a parameter which he then fills in for blaTime, therefore you could have the same thing you want but without Invoke. If you find out why Invoke didnt work tell me ^^ I didnt get it neither, but I also didnt knew about Invoke
Answer by herDev · Jan 16, 2017 at 02:53 PM
void Start()
{
StartCoroutine(MovementController(0)); //Note: there are 7 objects with this script
}
void manipulate()
{
if (Input.GetButtonDown("Manipulate Object") && !BlockInput)
{
Invoke("DoStuff", 0.0f);
print("MovementController call");
}
}
IEnumerator MovementController(float duration)
{
yield return new WaitForSeconds(duration);
DoStuff();
}
public void DoStuff()
{
print("MovementController respond");
//Do stuff
}
The call works that way, but the lerp over time is skipped (done by $$anonymous$$ovement while Timer < TimeLimit; Duration = TimeLimit - Timer).
Your answer
Follow this Question
Related Questions
Is there a way to show a warning when a Coroutine is called directly? 0 Answers
How to call function parameter 1 Answer
Changing mouse sensitivity 1 Answer
Calling Function in other Script via Touch => iOS Crash 1 Answer
I am trying to call another function in another script for an editor layout script. 1 Answer