error CS0161: not all code paths return a value

Idk what I did wrong. I’ve got code with “sNumber”. If sNumber is equal to 1 something happens, if 2/3/4/5/6 something different. If my sNumber option is finished it change snumber to 0 what starts xWP. Check this code:

	IEnumerator xWP()
	{
		int i;
		i = Random.Range (1, 6);
		sNumber = i;
	}

There’s something wrong. Whats wrong?

IEnumerator is the return type for a coroutine. Because of the nature of their implementation coroutines must be implemented over multiple frames. You can fake this like so.

IEnumerator xWP(){
    int i;
    i = Random.Range (1, 6);
    sNumber = i;
    yield return null;
}

Alternatively if you did not intend to write a coroutine then change the return type to void

void xWP() {
    int i;
    i = Random.Range (1, 6);
    sNumber = i;
}

try this

  IEnumerator xWP()
    {
        int i;
        i = Random.Range (1, 6);
        sNumber = i;
        yield return null;
    }

if you specify a type in the function declaration, unity(or any other complier) will require a return value of that type (or null)

so

int onePlusOne()
{
int answer;
answer = 1+1;
}

would generate your error, but

int onePlusOne()
{
int answer;
answer = 1+1;
return answer;
}

would work correctly