Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

How do I restructure my method to avoid the "not all code paths return a value" error?

$
0
0
If I check to see if the array is empty before I call the method, then I shouldn't need another return statement outside of the foreach loop because the loop will always return a value. How do I fix this? private bool CanPickupBug() { foreach (GameObject bug in bugs) { normalDistanceVector = (bug.transform.position - playerCamera.transform.position).normalized; distanceToBug = Vector3.Distance(bug.transform.position, playerCamera.transform.position); return (Vector3.Dot(normalDistanceVector, playerCamera.transform.forward) > lookTolerance && distanceToBug < distanceTolerance); } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>