When trying to enter play mode, I am receiving the error below:
error CS0161: `___': not all code paths return a value
The CS0161 error is caused when one or more outcomes of a method with a return type do not return a value.
In the example below we have a method that uses a GameObject as the return type. This means that all outcomes in this method must return a GameObject or the null value. The Script shown below does not return a value in all outcomes.
Here is how the error appears in this example:
error CS0161: `ExampleScript.SpawnEnemy(int)': not all code paths return
The error CS0161 is resolved by ensuring that all outcomes in the method return a value of the type defined. In this Example we have defined "GameObject" as the return type. We have fixed this example by ensuring that all outcomes return a value.