void OnTriggerEnter(Collider collision) { if (collision.gameObject.CompareTag("Player")) { MyAgent player = collision.gameObject.GetComponent <MyAgent>(); if (player.GetTeam() == team) { for (int i = player.GetCarrying() - 1; i > -1; i--) { GameObject currentTarget = player.GetCarry(i); capturedTargets.Add(currentTarget); int spot = AddToFirstSpotInBase(); Vector3 position = GetPosition(spot); currentTarget.GetComponent <Target>().AddToBase(spot, team, position); player.RemoveCarry(currentTarget); } } } }