- Home /
why am i getting this error?(not all code paths return a value)
got this code i dont know why im getting errors maybe someone can help me out thanks in advance :D something wrong with Coroutine i think but im not sure exactly i wouldnt normally post the entire script but its all bundled together anyway thanks for any help!
the exact errors are : error CS0161"shopelevel1.Open()": not all code paths return a value error CS0161"shopelevel1.Close()": not all code paths return a value
switch(state) {
case State.open:
state = shoplevel1.State.inbetween;
ForceClose();
break;
case State.close:
if(UI.Shop != null) {
UI.Shop.ForceClose();
}
state = shoplevel1.State.inbetween;
StartCoroutine("Open");
break;
}
}
private IEnumerator Open() {
UI.Shop = this;
_player = GameObject.FindGameObjectWithTag("Player");
inUse = true;
if(!_used)
Populate(5);
state = shoplevel1.State.open;
Messenger.Broadcast("DisplayShop");
}
private IEnumerator Close() {
_player = null;
inUse = false;
state = shoplevel1.State.close;
}
Answer by Rod-Green · Mar 24, 2012 at 03:10 PM
Your 'IEnumerator' methods need some kind of yield (Close and Open)..
i.e. yield return new WaitForSeconds(0.0f);
However why are they coroutines? Why not just
private void Close() & private void Open()
then force close would be
Open(); Close();
thank you! never used them before so should of done some research oh and there is good reason for coroutines later i want to use them for animations of the shop opening and closing and used them only because someone told me you can do that using coroutines but i had no idea how they worked but thank you !
Answer by koslovdenis · Jun 13, 2017 at 12:40 PM
Why in IEnumerator it is not possible to play sound???
How does this answer the (5 year old) question?
You can call AudioSource.Play() in a method that returns IEnumerator just fine.
Your answer
Follow this Question
Related Questions
Initialising List array for use in a custom Editor 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How can I save and load a Coroutine state ? 0 Answers
StopCoroutine Does Nothing 1 Answer