In my game the player can only move between MoveNodes. On colliding with the node, it adds the node name to a List. So as I travel around I amass a large list of previously visited MoveNodes.
On certain nodes a "back" button appears, which should send the player back to the 2nd most recent MoveNode in the List. How do I do this? Do I get the Length - 1 or something?
Also, can I clear anything but the most recent 5 objects in the list so it doesn't get so big?
asked May 21 '11 at 02:13 PM
Something like this (i'm assuming your array is called nodes):
We use "length-2" because nodes.length will return the length of the array BUT in a 5 node length array the elements will be in indexes 0,1,2,3, and 4. So to get at the second to last node we need to access the index that is 2 less than the length.
Once you have retrieved your node just set the players transform to the same as the node trnasform.
answered May 21 '11 at 02:55 PM
You can create a List of MoveNodes, then use the List functions Add, Remove, etc. and its property Item for managing and accessing the items as you want. You can see an example here:
The reference for the List methods and properties is here:
answered May 21 '11 at 02:54 PM