I am trying to make a function (in C#) that will return the first "empty" slot in an array.
Lets pretend I have an array that looks like this:
testarray[0] = Vector3(7,4,2);
testarray[1] = Vector3(9,12,5);
testarray[2] = Vector3(6,15,1);
testarray[3] = Vector3(0,0,0);
testarray[4] = Vector3(0,0,0);
testarray[5] = Vector3(13,8,5);
//...
In this example, the function would return 3, because 3 is the first time testarray contains an "empty" Vector3.
My attempts involve a for loop, but I still can't get it to work. Ill post my code so far, but if anyone has any other ideas, please help.
int FindFirst(Vector3[] array)
{
for (int i = 0; i <= thearraylength; i++)
{
if (array[i] == new Vector3(0f,0f,0f))
{
return i;
break;
}
}
}
↧