Join Jesse Freeman for an in-depth discussion in this video Getting the node index, part of Unity 5 2D: Pathfinding.
- View Offline
- Now it's time for us to complete our find node method.…We're going to need to create a simple…helper method that will allow us…to get a node from an index.…Let's create a public method, it'll return a type of int…and we'll call it get node index.…Inside of this method we're going…to pass in a node as well as a list of nodes.…From here we're going to iterate through the list…and compare to see if the node exists…inside of the list.…Let's create a four loop, we'll set i to zero…and we'll make sure that i is less than the list count.…
Next, we'll test if the node is equal…to the node in the list at the i index.…If it is, we'll return i.…At the bottom outside of our four loop…if we've not found the node in the list…we're going to return the value -1.…Now inside of our find node method…we can call the get node index.…From here we'll pass in the node we're searching…as well as the list that gets passed…into the find node method.…Then we'll do a compare to see if its greater than…or equal to zero.…
This way if we do find a node it'll return true.…
- What is A*?
- Adding node classes and properties
- Storing and indexing graph nodes
- Building the search class
- Traversing the nodes
- Searching adjacent nodes
- Testing the search
- Building a test map
- Creating and coloring a grid