// Start is called before the first frame update private void OnTriggerEnter2D(Collider2D other) { int collidedFoodId = other.GetComponent <FoodData>().id; int index = Global.selectedFoods.FindIndex(sf => sf.foodId == collidedFoodId); if (index > -1) { Global.selectedFoods[index].addOneToQuantity(); } else { InteractiveFood sf = new InteractiveFood(); sf.foodId = collidedFoodId; Global.selectedFoods.Add(sf); } other.GetComponent <FoodData>().addedToListAlready = true; print("total from entering trolley: " + Global.selectedFoods.Sum(item => item.quantity)); // print(Global.selectedFoods.Find(sf => sf.foodId == collidedFoodId).foodName + " " + Global.selectedFoods.Find(sf => sf.foodId == collidedFoodId).quantity); // string listitems = "items: "; // foreach(var item in Global.selectedFoods) { // listitems += item.foodName + " "; // } // print(listitems); // print(Global.selectedFoods.Count); }
private void rateSugar() { int sugarTotal = 0; for (int i = 0; i < Global.inBlenderFoods.Count; i++) { InteractiveFood currentFood = Global.inBlenderFoods[i]; int index = Global.foodData.FindIndex(data => data.id == currentFood.foodId); if (index > -1) { Food data = Global.foodData[index]; if (data.categoryName == "sometimes") { sugarTotal += data.sugarContent * currentFood.quantity; } } } if (sugarTotal <= 10) { generalisedScoreDict["sugar"] = Score.HIGH; } else if (sugarTotal <= 24) { generalisedScoreDict["sugar"] = Score.MEDIUM; } else { generalisedScoreDict["sugar"] = Score.LOW; } print("sugar score: " + generalisedScoreDict["sugar"]); }
private void sumCategories() { for (var i = 0; i < Global.inBlenderFoods.Count; i++) { InteractiveFood currentFood = Global.inBlenderFoods[i]; int index = Global.foodData.FindIndex(data => data.id == currentFood.foodId); if (index > -1) { string currentCategory = Global.foodData[index].categoryName; categoryDict[currentCategory] += currentFood.quantity; } } }
private void OnTriggerEnter2D(Collider2D other) { int collidedFoodId = other.GetComponent <FoodData>().id; int index = Global.inBlenderFoods.FindIndex(bf => bf.foodId == collidedFoodId); if (index > -1) { Global.inBlenderFoods[index].addOneToQuantity(); } else { InteractiveFood ibf = new InteractiveFood(); ibf.foodId = collidedFoodId; Global.inBlenderFoods.Add(ibf); } other.GetComponent <FoodData>().addedToListAlready = true; other.GetComponent <DraggableFoodController>().isScaledDown = true; Bounds bounds = gameObject.GetComponent <PolygonCollider2D>().bounds; other.GetComponent <DraggableFoodController>().moveObjectToCenterOfBlender(bounds); }