You can cook
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class CookButton : MonoBehaviour
|
||||
{
|
||||
public GameObject Button;
|
||||
|
||||
void OnMouseUp() {
|
||||
Debug.Log("L");
|
||||
Button.GetComponentInParent<Cooking>().CreateDish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,21 @@ public class Cooking : MonoBehaviour
|
||||
|
||||
public Vector3 FinishedDishPosition;
|
||||
|
||||
void CreateDish() {
|
||||
public void CreateDish() {
|
||||
List <GameObject> Ingredients = GetIngredients();
|
||||
|
||||
List <GameObject> AllDishes = new List <GameObject>();
|
||||
|
||||
// Find all dishes ingredients can make
|
||||
|
||||
if (Ingredients.Count < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (GameObject Ingredient in Ingredients) {
|
||||
|
||||
Debug.Log(Ingredient.name);
|
||||
|
||||
List <GameObject> Dishes = Ingredient.GetComponent<Ingredient>().IngredientIn;
|
||||
|
||||
foreach (GameObject Dish in Dishes) {
|
||||
@@ -76,8 +83,22 @@ public class Cooking : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Remove ingredients and add the dish
|
||||
// Find used ingredients
|
||||
List <GameObject> IngredientsInDish = BestDish.GetComponent<Dish>().RequiredIngredients;
|
||||
List <GameObject> UsedIngredients = new();
|
||||
List <GameObject> UnusedIngredients = new();
|
||||
|
||||
foreach (GameObject Ingredient in Ingredients) {
|
||||
if (IngredientsInDish.Contains(Ingredient)) {
|
||||
UsedIngredients.Add(Ingredient);
|
||||
}
|
||||
else {
|
||||
UnusedIngredients.Add(Ingredient);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove ingredients and add the dish
|
||||
foreach (GameObject Ingredient in UsedIngredients) {
|
||||
Transform transform = Ingredient.GetComponent<Ingredient>().transform;
|
||||
transform.position = Vector3.up * 50;
|
||||
}
|
||||
@@ -91,14 +112,20 @@ public class Cooking : MonoBehaviour
|
||||
List <GameObject> currentCollisions = new List <GameObject>();
|
||||
private void OnTriggerEnter2D(Collider2D other) {
|
||||
currentCollisions.Add (other.gameObject);
|
||||
CreateDish();
|
||||
}
|
||||
private void OnTriggerExit2D(Collider2D other) {
|
||||
currentCollisions.Remove (other.gameObject);
|
||||
}
|
||||
List <GameObject> GetIngredients()
|
||||
{
|
||||
return currentCollisions;
|
||||
List <GameObject> Ingredients = new List <GameObject>();
|
||||
|
||||
foreach (GameObject collision in currentCollisions) {
|
||||
if (collision.tag == "Ingredient") {
|
||||
Ingredients.Add(collision);
|
||||
}
|
||||
}
|
||||
return Ingredients;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user