Trying to remove a specific object from my list on trigger exit is prooving difficult for some reason.
As you can see i’ve done everything i can to try to debug this using print and Debug.Break… i’ve narrowed it down to when comparing the GetInstanceID is failling. If removing objects from a list/array is it ok to iterate backwards through the list/array?
Some help would be greatly apreciated!
function OnTriggerExit(other : Collider) {
print(other.transform.GetInstanceID());
if(other.transform.tag == "Cube")
{
if(cubeList.Count != 0)
{print("iterating through Cube List");
for(var i : int = cubeList.Count-1; i >= 0; i--)
{
print("in iteration loop");
var currentCubeObject : GameObject = cubeList*;*
-
print("the current cube ID " + currentCubeObject.GetInstanceID());* -
if(currentCubeObject.GetInstanceID() == other.transform.GetInstanceID())* -
{ cubeList.RemoveAt(i); Debug.Break();}* -
if (i == cubeList.Count) {break;}* -
}* -
//cubeList.RemoveAt(cubeList.Count-1);* -
//print("cube exited the colum " + transform.name);* -
//print("break for cube removal from " + transform.name);* -
//Debug.Break();* -
}* -
}*
}