Hey Unity peeps,
I have a custom class that can have any number of instances generated at runtime. I am building a very literal "snapping" matrix (multi-dimensional, jagged array) specific to each instance of the class. The issue is that all instances of the class seem to be manipulating the same array instead of their own instance of said "private" array (snapToLocation).
// da class
class LineObject {
private var name : String;
private var id : int;
private var startPoint : Vector2;
private var endPoint : Vector2;
private var lineLength : float;
private var maxLength : int = 12;
private var snapToLocation = Array(maxLength);
public function LineObject () {
// prep item "snapping" matrix
for (var i : int = 0; i < maxLength; i++) {
snapToLocation[i] = new Array(3);
snapToLocation[i][0] = "available";
snapToLocation[i][1] = "available";
snapToLocation[i][2] = "available";
}
}
// getters, setters, etc...
}
// and elsewhere ... da instantiation
function CreateLineObject (line, id) : LineObject {
var vectorPoints : Vector2[] = line.points2;
var startPoint : Vector2 = vectorPoints[0];
var endPoint : Vector2 = vectorPoints[1];
var lineLength : float = line.GetLength();
var newLineObject = new LineObject();
newLineObject.SetName(line.name);
newLineObject.SetID(id);
newLineObject.SetStart(startPoint);
newLineObject.SetEnd(endPoint);
newLineObject.SetLength(lineLength);
return newLineObject;
}
Any help would be greatly appreciated! Cheers and hats off to the CommUnity!
↧