Waypoint foreach issue

I’ve following the course up to the point where ben does dictionary data structure and in my pathfinder scropt, I’m getting this error from my foreach statement which states that " Foreach statements cannot operate on variables of type ‘Waypoint’ because ‘Waypoint does not contain a public instance definition for "GetEnumerator’ " Here is my pathfinder code:


Just in case here’s the waypoint script as well (upload://qWD7MqsJxpvreKj6eS6zPG3ABdZ.jpeg)

1 Like

In future please take screenshots or use a pastebin / gist service to place your code and link it here (there’s also a code markdown tag you can use to just put it straight in the post).

The reason you can’t loop or iterate over multiple waypoints, is that waypoints is not an array or container type, just a single waypoint object.

On line 16 you’ll see you requested to FindObjectOfType (singular), and not FindObjectsOfType (plural).

https://docs.unity3d.com/ScriptReference/Object.FindObjectsOfType.html

1 Like

Thanks I solved the issue and I took a picture because my computer was being complicating and I had no time

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms