Hey guys, have a little code here that should put pickedup gameobjects in an Array.
The following code generates this error:
“ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count”
code:
var objectarray: Array = new Array();
var arraycount:int = 0;
function Update () {
}
function AddObject(o:GameObject){
print("ObjectInventory: Object Added");
objectarray.Add(o);
arraycount = objectarray.length;
print(objectarray);
objectarray[arraycount].transform.position = Vector3(11, 0.7, -21.45);
}
If I set a hard index int (like 0), the code works, but not when I derive it from objectarray.length.
I tried arraycount = int(objectarray.length);
But that doesn’s seem to wrk either.
Anyone any tips? Much appreciated!