Before updating to Windows 10 you may need to return your Pro license. More information here

Create array of children in Start function, use it in Update?

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 () { WayPoints.Add(WayPointContainer.GetComponentsInChildren(Transform)); Debug.Log(WayPoints[CurrentWayPoint].position); }

function Update () { if(transform.position.x != WayPoints[CurrentWayPoint].position.x) { //move } }

the error I get is ; ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count. Parameter name: index 1

does this mean it isn't adding the transforms of the children? if so how do I fix this?

more ▼

asked Apr 30, 2011 at 09:54 AM

avatar image

Jason Hamilton
530 194 148 153

Remember to use WayPoints.Shift() after adding the children to remove the parent.

Apr 30, 2011 at 12:55 PM Joshua
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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).

more ▼

answered Apr 30, 2011 at 12:14 PM

avatar image

5.7k 41 62 114

But enemywaypointcontainer has 2 children, so the parent is 0 and the two children are 1,2?

May 01, 2011 at 05:10 AM Jason Hamilton

Instead of Add(), try AddRange().

May 01, 2011 at 12:22 PM Molix

is that something available with javascript arrays?

May 02, 2011 at 07:25 AM Jason Hamilton

Yes, they do have it.

May 02, 2011 at 02:23 PM Molix
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Apr 30, 2011 at 09:54 AM

Seen: 2371 times

Last Updated: Apr 30, 2011 at 09:54 AM