Hello
I keep having this problem “Update() can not be a coroutine.” popping up in my console. What I am attempting to make is a menu. What the script that is showing the error does is handle changing the selected button in the menu and changing scene depending on what button is checked.
Here is my code
`
var Menu : int = 1;
function Start () {
}
function Update ()
{
if (Input.GetKeyDown (KeyCode.UpArrow))
{
Menu = Menu + 1;
yield WaitForSeconds (1);
}
if (Menu > 5)
{
Menu = 1;
}
if (Input.GetKeyDown (KeyCode.UpArrow))
{
Menu = Menu - 1;
yield WaitForSeconds (1);
}
if (Menu < 1)
{
Menu = 5;
}
if(Input.GetKeyDown(KeyCode.Return) && (Menu == 1));
{
Application.LoadLevel("Multiplayer");
}
if(Input.GetKeyDown(KeyCode.Return) && (Menu == 2));
{
Application.LoadLevel("Career");
}
if(Input.GetKeyDown(KeyCode.Return) && (Menu == 3));
{
Application.LoadLevel("Challenges");
}
if(Input.GetKeyDown(KeyCode.Return) && (Menu == 4));
{
Application.LoadLevel("Free Race");
}
if(Input.GetKeyDown(KeyCode.Return) && (Menu == 5));
{
Application.LoadLevel("My Garage");
}
}`
As you can see its a pretty plain and simple script just handling changing the scene. My problem is that I get the error “Update() can not be a coroutine.” From my research its because the Update Function cannot handle yield. However I have tried using the CoUpdate function but that does not work. Because of this one of my questions is what function is recommended to use in place of Update. If I take out the yield for some reason it goes to the “My Garage” scene even though I dont press any button and the Menu variable = 1.
Although I am sure that the answer is simple I cant seem to figure it out.
Thanks In advance
Thank you I believe that that will work
– Dok101Like SinisterRainbow said you cannot yield in Update only in Coroutines. Take a look [Here][1] loads of great info .. [1]: http://unitygems.com
– GriffoI already knew that you couldnt use yield in Update. Thank you though for the link I will check that out
– Dok101@Griffo Sorry but for some weird reason I still get Update() cannot be a corountine
– Dok101Sorry missed line 50 out }
– Griffo