Array of custom class objects all return the same value?

I'm having trouble with a system of creating waypoints and the way that my custom waypoint class is being referenced. My code is as follows:

in a file called Waypoints attached to my Player

public var location: Vector3;
public var attitude: Quaternion;
public var pathType:int;

function SetWayPoint(tr_Loc:Vector3,tr_Rot:Quaternion,pT:int){
location = tr_Loc;
attitude = tr_Rot;
pathType = pT;
}

in a file called PathCreate attached to my Player

var wayPts: Waypoints[] = new Waypoints[21];

function FirstMove() {
wayPts[0].SetWayPoint (transform.position,transform.rotation,1);
wayPts[1].SetWayPoint (transform.position,transform.rotation,2);
wayPts[2].SetWayPoint (transform.position,transform.rotation,3);

print(wayPts[0].pathType+" "+wayPts[0].pathType+" "+wayPts[0].pathType);
}

If I run the program and call "FirstMove()", I get a "NullReferenceException: Object reference not set to an instance of an object"

If I go to the Player in the Inspector and select the PathCreate script, then select the elements of "Way Pts" and change them from "None (Waypoints)" to "Player (Waypoints)" [based on the pull-down], the program runs with no error, but my printed output is "3 3 3" instead of the expected "1 2 3". I'm guessing this means that all of the waypoints in the array are writing to the single waypoint data from the script, but I don't know how to prevent this. Any help would be appreciated! Thanks!

Initializing the array of WayPoints doesn't initialize each instance of Waypoints. So after new Waypoints[21] is called, you have an array of size 21 that points to 21 null Waypoints objects.

Now if Waypoints has to be a MonoBehaviour you're kind of out of luck unless you hook things up in the editor, but if you just want your Waypoints class to be a thin wrapper for position and rotation data you could just make it a c# struct so you don't have to do anything (all value types get initialized to zero). Or you could make it a c# class, but you'd have to new off each instance of it like this:

wayPts[0] = new WayPoints();
wayPts[0].SetWayPoint( /*whatever*/ );

I don't know how you'd go about doing that in Javascript, though, since all classes are assumed to derive from MonoBehaviour.

Edit: If you want to add a bunch of waypoint objects, do this:

wayPts[0] = AddComponent( "WayPoints" );
wayPts[0].SetWayPoint( /*whatever*/ );