- Home /
"Script Error: Update() can not be a coroutine". when i add an If statement, I get this error message on the console, not monodevelop.
This is the Script. var numberOfJumps : float; var jumpForce : float =3;
function Update()
{
if(Input.GetButtonUp("Jump")){
rigidbody.AddForce(Vector3.up * jumpForce * 100);
numberOfJumps += 1;}
**if (numberOfJumps == 2){
yield WaitForSeconds(4);
numberOfJumps = 0;}**
}
Once I added the second if statement, there are no errors or warnings, but the script just wont work, cant even jump. while running the game I get "Script Error: Update() can not be a coroutine". thanks a lot.
Answer by kumarc123 · Aug 26, 2013 at 09:17 AM
Update gets called for every frame. So it cannot be IEnumerable, i.e., it cannot be a co-routine.
From your I have observed that after pressing jump button you want to stop update for 4 seconds.
Instead of doing it try to cut and paste the jump code in a method which is coroutine and call it in update.
Your problem will get solved
Thanks a lot. I had solved it already but that was probably one of the best explanations of how that works :)
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
how do I script this jump animation? 1 Answer
Trouble with Iterative Coroutine 1 Answer
While loop yield lag? 1 Answer
Addforce to create a gliding effect? 2 Answers