Accessing Vector3s of GameObjects in Arrays (JS)

Hello,

I’m having trouble accessing the transform and rotational data of nodes stored in a Javascript array. I either can’t find the proper syntax, or am approaching the problem incorrectly.

This script finds all of the camera nodes (by tag ‘Camera Node’) and stores them in an array. It then attempts to access the transforms of those GameObjects so that it can move the camera to them.

My code (JS):
`
// VARIABLES FOR CAMERA NODES
var cameraNodes = new Array ();
var currentCamera : int = 0;
var nextCamera : int;

function Start () {

	// Find Nodes
	cameraNodes = GameObject.FindGameObjectsWithTag("CameraPos");


}

function MoveNext () {

	nextCamera = (currentCamera + 1);

    // Determine if nextCamera is bigger than array
	if (nextCamera > cameraNodes.length) {
	
		nextCamera = 0;
	
	}

	Debug.Log("I am going to cameraPosition " + (nextCamera + 1));
	iTween.MoveTo(gameObject,(cameraNodes[nextCamera].Vector3),2);
	
	currentCamera = nextCamera;
	

}

`

A few changes here. First, declare ‘cameraNodes’ as:

var cameraNodes : GameObject[];

You don’t need to initialize an array for ‘cameraNodes’ since FindGameObjectsWithTag() returns an array. Plus if you need a collection for a list of game objects, use the .NET generic List class rather than the Array class.

Then on line 21, you can access the nodes as ‘cameraNodes[nextCamera].transform.position’

iTween.MoveTo(gameObject,cameraNodes[nextCamera].transform.position, 2.0);