private void OnTriggerEnter(Collider other) { //check if the trigger is a santa and the house is selected by the same santa if (other.gameObject.tag == "Santa" && isSelected == true && santasId.Contains(other.gameObject.GetComponent <Santa>().id)) { //check if the santa have the associated gift Santa touchedSanta = other.gameObject.GetComponent <Santa>(); bool isSantaHaveAssociatedGift = false; int i = 0; while (i < associatedGifts.Count) { if (touchedSanta.collectedGifts.Contains(associatedGifts[i])) { //deliver the gift SantaGameManager.Instance.DeliveredGift(associatedGifts[i]); //Remove the gift from the santa touchedSanta.DeliverGift(associatedGifts[i]); //Remove the gift from the santa gift UI list if the scroll view is enabled and if the active scroll view content is corresponding to the selected santa if (SantaMainController.Instance.SantaScrollViewObject.activeInHierarchy && InputManager.Instance.selectedSanta.GetComponent <Santa>().id == touchedSanta.id) { //Refresh the scroll view SantaMainController.Instance.ClearSantaScrollView(); SantaMainController.Instance.InitSantaScrollView(touchedSanta.collectedGifts); } //Remove the gift from house associatedGifts.Remove(associatedGifts[i]); //Set the boolean is have associated gift to true isSantaHaveAssociatedGift = true; } else { i++; } } //remove the santa id santasId.Remove(touchedSanta.id); //If the santa doesn't have the associated gift delete the destination if (!isSantaHaveAssociatedGift) { touchedSanta.touchWaypoint(); } //Check if all gifts are delivred if (associatedGifts.Count == 0) { //Dishighlight the house GetComponent <Outline>().enabled = false; //Set the house non clickable gameObject.layer = 0; } } }