After some searching and getting more confused i thought i would post my question.
i would like to compare two builtin arrays in the following way:
first object has an array of objects
second object also has an array that may or may not contain some of the objects from the first one
if my array contains any of the first objects array, remove them.
i know how to rebuild, its the finding / looping part that has me stumped. the items indexes most likely will be in random order in the builtin arrays.
pseudo code:
var myArray : GameObject[];
var otherGameObjectScript : otherGameObjectScript;
function CheckIfInOther()
{
var otherArray = otherGameObjectScript.myArray;
for (var i : GameObject in otherArray)
{
if (i is in myArray)
{
remove i and rebuild myArray;
}
}
}
This would be a simple process using C# and LINQ but you’d need to think about how often you’re doing it. So, the simplest way would be to recreate the array. This is ok if you’re not doing it often, but if it’s an every frame type of thing you won’t want to do it.
Since you’re using an array of GameObject the above code would probably be the best, otherwise you’d have to remove the items, reorganize the existing items, and then resize your array. In your example code above, just so you know, you won’t be able to do exactly what you want… however if you’re using a List this gets easier because you could use myArray.Contains(itm) and if it’s there call Remove on it.