/// <summary> /// Sent each frame where another object is within a trigger collider /// attached to this object (2D physics only). /// </summary> /// <param name="other">The other Collider2D involved in this collision.</param> void OnTriggerStay2D(Collider2D other) { if (other.gameObject.tag == "DraggableElement" && canCollide == true && gameObject.GetComponent <ElementDragHandler>().dragging == false) { //Destroy(other.gameObject); Image image = other.gameObject.GetComponent <Image>(); Color newColor = new Color(image.color.r, image.color.g, image.color.b, 1); image.color = newColor; //RecipeDictionary d = new RecipeDictionary(); // finds the index of the element created. Returns -99 if no recipe found. int elementIndex = IsValidRecipe(this, other.gameObject.GetComponent <DraggableElement>()); //when the a spell is casted destroy the ingredients if (elementIndex > 89 && ((elementIndex != 92) && (elementIndex != 109))) { Destroy(this.gameObject); Destroy(other.gameObject); } // unlock spell cSpell.ToggleCheckmark(elementIndex); //if wine recipe is completed return the wine sprite if (elementIndex == 92) { elementIndex = 9; } //shrinking spell is completed return a tiny tray else if (elementIndex == 109) { elementIndex = 24; } // make sure valid element can be added (out of bounds) if (elementIndex != -99 && elementIndex < 89) { other.gameObject.GetComponent <DraggableElement>().image.sprite = elDic.allElements[elementIndex].icon; other.gameObject.GetComponent <DraggableElement>().elementID = elDic.allElements[elementIndex].elementID; other.gameObject.GetComponent <DraggableElement>().nameText.text = elDic.allElements[elementIndex].elementName; other.gameObject.GetComponent <DraggableElement>().element = elDic.allElements[elementIndex]; //check if this element has not been discovered if (!elDic.allElements[elementIndex].active) { // set created element to active elDic.allElements[elementIndex].active = true; // add element to UI inventory PopulateGrid unlockedItems = FindObjectOfType <PopulateGrid>(); unlockedItems.AddItem(elementIndex); // check if beast pelt if (elementIndex == 62) { // set beast blood and hair to active elDic.allElements[63].active = true; unlockedItems.AddItem(63); elDic.allElements[64].active = true; unlockedItems.AddItem(64); } // check if blood else if (elementIndex == 17) { // set beast blood and hair to active elDic.allElements[20].active = true; unlockedItems.AddItem(20); } // Play New discovery sound effect audio.PlayNewCombo(); } else { // play regular Combination sound effect audio.PlayCombo(); } // check if beast pelt if (elementIndex == 62) { // spawn beast blood and hair myItem.SpawnBeastItem(); } // check if blood else if (elementIndex == 17) { // spawn human eye myItem.SpawnHumanItem(); } Destroy(this.gameObject); } else { // play no combo sound ONCE!!! if (!soundPlayed) { audio.PlayNoCombo(); soundPlayed = true; } } } }