void OnTriggerEnter2D(Collider2D col) { // PICKUP FRUIT: // Loop through list of fruitnames to se which is triggered. for (int i = 0; i < fruitNames.Length; i++) { // Break out of loop when no more fruits can be held. if (currentlyHolds == canOnlyHold) { break; } // If gameObject.tag == respective fruit. if (col.gameObject.tag == fruitNames[i]) { // Count fruit. currentlyHolds++; fruitCount[i]++; fruitCountTotal[i]++; // Set sprite for fruit that is held by player. if (isFirstCarryFruitOpen == false && currentlyHolds == 1) { r1.SetFruit(i); } else if (isFirstCarryFruitOpen == false && currentlyHolds == 2) { r2.SetFruit(i); } else if (isFirstCarryFruitOpen == false && currentlyHolds == 3) { r3.SetFruit(i); } // Special case when first fruit is put on glass and more fruit is to be picked up. // Must fill in open slot on. else if (isFirstCarryFruitOpen == true) { r1.SetFruit(i); isFirstCarryFruitOpen = false; } // Fading text appears when fruit is picked up. InstantiateTextMesh(fruitNames[i]); // First fruit that is picked up is stored. if (!isFruitOnGlass && glassFruit == "") { glassFruit = fruitNames[i]; glassFruitIndex = i; } // Destroy object(fruit) when triggered. Destroy(col.gameObject); } } // EMPTY FRUIT: // Empty fruits here and check if all fruits are collected. if (currentlyHolds != 0 && levelFinished == false && col.gameObject.tag == "Blender") { // Check glass for fluid. CheckFluid(fruitCountTotal.Sum()); // Start blender animation and send fruitCount so right fruit color can be set on fluid. b.BlenderAction(fruitCount, ""); // Remove sprite from player so he doesn't carry any fruit. 80 is a default value. r1.SetFruit(80); r2.SetFruit(80); r3.SetFruit(80); if (!hasSpilled) { // Check if fruits to complete leves has been collected. returnValue = checkLevel.LevelCheck(currentLevel, fruitCount, currentlyHolds, ""); } currentlyHolds = 0; p.SetCollected(checkLevel.Counter()); if (returnValue == "Finished") { ReadyForNextLevel(); } else if (returnValue != "") { WrongFruit(returnValue); } // For each fruit. for (int i = 0; i < fruitNames.Length; i++) { // For each count of that fruit. for (int j = 0; j < fruitCount[i]; j++) { // Drop as many fruits as in fruitCount into blender. d.DropIntoBlender(fruitNames[i]); } // Reset fruitCount. fruitCount[i] = 0; // No fruit were put on glass. Reset values. glassFruit = ""; } } // PUT FRUIT ON GLASS. if (currentlyHolds != 0 && levelFinished == false && isFruitOnGlass == false && col.gameObject.tag == "Glass") { // Places fruit on glass. d.DropIntoGlass(glassFruit); // Set bool value and decrement fruitCount of fruit that was put on glass. isFruitOnGlass = true; fruitCount[glassFruitIndex]--; fruitCountTotal[glassFruitIndex]--; // Remove sprite from player so he doesn't carry first fruit. 80 is a default value. r1.SetFruit(80); isFirstCarryFruitOpen = true; // Check if fruits to complete leves has been collected. returnValue = checkLevel.LevelCheck(currentLevel, fruitCount, currentlyHolds, glassFruit); currentlyHolds--; p.SetGlassCollected(checkLevel.GlassCounter()); if (returnValue == "Finished") { ReadyForNextLevel(); } else if (returnValue != "") { WrongFruit(returnValue); } } } // End of function.