food position fix

This commit is contained in:
2024-04-03 09:45:30 +02:00
parent 5646ed6504
commit 7c026e34ff
5 changed files with 308 additions and 297 deletions

View File

@@ -56,5 +56,5 @@
"temp/": true, "temp/": true,
"Temp/": true "Temp/": true
}, },
"dotnet.defaultSolution": "Let-Him-Cook.sln" "dotnet.defaultSolution": "Let Him Cook.sln"
} }

File diff suppressed because it is too large Load Diff

View File

@@ -15,6 +15,7 @@ public class Cooking : MonoBehaviour
// } // }
public Vector3 FinishedDishPosition; public Vector3 FinishedDishPosition;
public GameObject AllIngredients;
public void CreateDish() { public void CreateDish() {
List <GameObject> Ingredients = GetIngredients(); List <GameObject> Ingredients = GetIngredients();
@@ -29,8 +30,6 @@ public class Cooking : MonoBehaviour
foreach (GameObject Ingredient in Ingredients) { foreach (GameObject Ingredient in Ingredients) {
Debug.Log(Ingredient.name);
List <GameObject> Dishes = Ingredient.GetComponent<Ingredient>().IngredientIn; List <GameObject> Dishes = Ingredient.GetComponent<Ingredient>().IngredientIn;
foreach (GameObject Dish in Dishes) { foreach (GameObject Dish in Dishes) {
@@ -97,14 +96,27 @@ public class Cooking : MonoBehaviour
} }
} }
// Remove ingredients and add the dish // // Remove ingredients and add the dish
// foreach (GameObject Ingredient in UsedIngredients) {
// Transform transform = Ingredient.GetComponent<Ingredient>().transform;
// transform.position = Vector3.up * 50;
// }
BestDish.transform.position = FinishedDishPosition;
foreach (GameObject Ingredient in UsedIngredients) { foreach (GameObject Ingredient in UsedIngredients) {
Transform transform = Ingredient.GetComponent<Ingredient>().transform; Transform transform = Ingredient.GetComponent<Ingredient>().transform;
transform.position = Vector3.up * 50; transform.position = Vector3.up * 50;
} }
BestDish.transform.position = FinishedDishPosition; // Return ingredients to table
for (int i = 0; i < AllIngredients.transform.childCount; i++)
{
GameObject ingredient = AllIngredients.transform.GetChild(i).gameObject;
ingredient.GetComponent<Ingredient>().ResetPosition();
}
} }

View File

@@ -5,18 +5,26 @@ using UnityEngine;
public class Dish : MonoBehaviour public class Dish : MonoBehaviour
{ {
public List <GameObject> RequiredIngredients; public List <GameObject> RequiredIngredients;
public int NutritionalValue; public int NutritionalValue = 0;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
if (NutritionalValue > 0) {
return;
} }
// Update is called once per frame NutritionalValue = 0;
void Update()
{ foreach (GameObject Ingredient in RequiredIngredients) {
int IngredientValue = Ingredient.GetComponent<Ingredient>().NutritionalValue;
NutritionalValue += IngredientValue;
} }
} }
}

View File

@@ -12,9 +12,10 @@ public class Ingredient : MonoBehaviour
public int NutritionalValue; public int NutritionalValue;
bool isMoving = false; bool isMoving = false;
//public GameObject table; //public GameObject table;
private Transform DefaultTransform;
void Start() void Start()
{ {
DefaultTransform = transform; //TODO pointer error
} }
// Update is called once per frame // Update is called once per frame
@@ -24,9 +25,10 @@ public class Ingredient : MonoBehaviour
{ {
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3 (mousePosition.x, mousePosition.y, transform.position.z); transform.position = new Vector3 (mousePosition.x, mousePosition.y, transform.position.z);
//Debug.Log(table.Bounds.Contains(mousePosition));
} }
ResetPosition();
} }
@@ -37,4 +39,12 @@ public class Ingredient : MonoBehaviour
else else
isMoving = true; isMoving = true;
} }
public void ResetPosition()
{
transform.position = DefaultTransform.position;
Debug.Log(gameObject.name);
Debug.Log(transform.position);
Debug.Log(DefaultTransform.position);
}
} }