Hey, so what I'd like to do is make an array of children, then move the player to the child in the the array that I choose, heres the code;
WayPointContainer is an empty gameobject with empty gameObjects as children.
var WayPoints = new Array();
var WayPointContainer : Transform;
private var CurrentWayPoint : int = 1;
function Start ()
function Start ()
function Update ()
if(transform.position.x != WayPoints[CurrentWayPoint].position.x)
the error I get is ;
ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index
does this mean it isn't adding the transforms of the children? if so how do I fix this?
Remember to use WayPoints.Shift() after adding the children to remove the parent.
Answer by Molix
Apr 30, 2011 at 12:14 PM
Array indices start at 0. You have only one item, so to access it you need to use index 0, but CurrentWayPoint is 1 (that is the argument that is out of range).
But enemywaypointcontainer has 2 children, so the parent is 0 and the two children are 1,2?
Instead of Add(), try AddRange().
Yes, they do have it.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
No one has followed this question yet.
IndexOutOfRangeExeption: Array index is out of range
for loop error
GetComponents array in C# error ?
IndexOutOfRangeExeption - Array index is out of range