Question by
Jdlennox03 · Apr 19 at 04:21 PM ·
unity 2d
GameObject using my script individually instead of sharing
So I'm trying to to check what ingredients are in boxes then make them into a list so that I can then turn the list into an array and compare it to deferent recipes but each of the boxes are using it's own individual script instead of a shared one which is the problem. Dose anyone Know the fix for this ?
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlateBoxsCollishion : MonoBehaviour
{
Collider2D NamedObject;
Collider2D TB;
string TagHolder;
List<GameObject> Ingredients = new List<GameObject>();
List<string> InBox = new List<string>();
public int Int;
public string[] allTemp;
int count;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//TB = this.GetComponent<Collider2D>();
//if (TB = null)
{
// Debug.Log("TB is null");
}
count = Ingredients.Count;
Debug.Log("Count is" + count);
foreach (GameObject item in Ingredients)
{
Debug.Log("foreach started");
Debug.Log("Adding this ingrediant to list" + Ingredients[Int]);
string temp;
temp = Ingredients[Int].gameObject.name;
Debug.Log("temp is " + temp);
InBox.Add(temp);
Int++;
Debug.Log("inbox list is " + string.Join(", ", InBox) + "int=" + Int);
}
}
void OnTriggerEnter2D(Collider2D col)
{
Debug.Log("collide (name) : " + col.gameObject.name);
Debug.Log("collide (tag) : " + col.gameObject.tag);
// get collided food object name, and hold it
string Name = col.gameObject.name;
Debug.Log("collide name : " + col.gameObject.name);
//get the named objects collider
col = GameObject.Find(Name).GetComponent<Collider2D>();
NamedObject = col;
TagHolder = NamedObject.gameObject.tag;
CheckTag();
}
void OnTriggerExit2D(Collider2D col)
{
GameObject.Find("SliderCooking").GetComponent<CookingSlider>().enabled = false;
Debug.Log("Deactivate");
}
void CheckTag()
{
if (TagHolder == "Chopped")
{
//Debug.Log("Tag is" + TagHolder);
}
else if (TagHolder == " Chopped&Cooked")
{
if (NamedObject.bounds.Intersects(TB.bounds))
{
Ingredients.Add(NamedObject.gameObject);
Debug.Log("added to list " + NamedObject.gameObject.name);
Debug.Log("first ingrediants is" + Ingredients[0]);
}
}
else
{
Debug.Log("NoTagFound");
//no tag
//remove
Ingredients.Add(NamedObject.gameObject);
Debug.Log("added to list " + NamedObject.gameObject.name);
Debug.Log("first ingrediants is" + Ingredients[0]);
recipes();
}
}
void recipes()
{
//if (NamedObject.bounds.Intersects(TB.bounds))
// {
// Ingredients.Add(NamedObject.gameObject);
//}
//else if (NamedObject = null)
//{
// Debug.Log("NoNamedObject");
//}
string[] TomatoSoup = { "Onion", "Carrot", "Tomato", "Stock" };
string[] OxtailSoup = { "Onion", "Carrot", "Octail", "Stock", "Flour" };
string[] LambPattie = { "Lamb", "Onion", "Garlic", "Bread" };
string[] Carbonara = { "Pasta", "Egg", "Cheese", "Garlec", "Bacon" };
string[] ShepherdPie = { "Onion", "Carrot", "Lamb", "Bacon", "Potato" };
string[] BeefSrew = { "Beef", "Carrot", "Stock", "Potato" };
string[] Pizza = { "Flour", "Tomato", "Cheese", "Bacon" };
string[] YeOldeGrilledCheese = { "Bread", "Cheese" };
string[] SmileyBurger = { "Beef", "Bread", "Lettuce" };
string[] MrWhiskersPancakes = { "Flour", "Egg", "Milk" };
string[] ApplePie = { "Pastry", "Apple", "Sugar", "Cinnamon" };
string[] MeowchiMochiIceCream = { "IceCream", "RiceFlour" };
string[] RicePudding = { "Rice", "Milk", "Sugar" };
string[] Meringue = { "Egg", "Sugar" };
Array.Sort(TomatoSoup);
Array.Sort(OxtailSoup);
Array.Sort(LambPattie);
Array.Sort(Carbonara);
Array.Sort(ShepherdPie);
Array.Sort(BeefSrew);
Array.Sort(Pizza);
Array.Sort(YeOldeGrilledCheese);
Array.Sort(SmileyBurger);
Array.Sort(MrWhiskersPancakes);
Array.Sort(ApplePie);
Array.Sort(MeowchiMochiIceCream);
Array.Sort(RicePudding);
Array.Sort(Meringue);
Debug.Log("tomato soup is ? "+ TomatoSoup.ToString());
Debug.Log(string.Join(", ", TomatoSoup));
Debug.Log("ingrediants is " + Ingredients[0]);
//Debug.Log("ingrediants is" + Ingredients[1]);
//Debug.Log("ingrediants is" + Ingredients[2]);
//Debug.Log("ingrediants is" + Ingredients[3]);
// Debug.Log("ingrediants is" + Ingredients[4]);
//int count = Ingredients.Count;
//Debug.Log("Count is"+ count);
//List<string> InBox = new List<string>();
//int Int = 0;
//string temp;
//string[] allTemp;
//Int = count;
//foreach (GameObject item in Ingredients)
{
//Debug.Log("foreach started");
//Debug.Log("Adding this ingrediant to list"+ Ingredients[0]);
//temp = Ingredients[Int].gameObject.name;
//Debug.Log("temp is " + temp);
//InBox.Add(temp);
//Int ++;
//Debug.Log("inbox list is " + string.Join(", ", InBox) + "int=" + Int);
}
//allTemp = InBox.ToArray();
//Debug.Log("array alltemp is");
//Debug.Log(string.Join(", ", allTemp));
//string temp0 = Ingredients[0].gameObject.name;
//string temp1 = Ingredients[1].gameObject.name;
//string temp2 = Ingredients[2].gameObject.name;
//string temp3 = Ingredients[3].gameObject.name;
//string temp4 = Ingredients[4].gameObject.name;
// string[] Alltemp = { temp0 }; // temp1, temp2, temp3, temp4 };
//Array.Sort(Alltemp);
//Debug.Log(string.Join(", ", Alltemp));
//Debug.Log("All tempo ingrediants " + Alltemp + temp0 + temp1 + temp2 + temp3 + temp4);
//if (Alltemp.Contains(TomatoSoup))
{
}
}
public void PlateButton()
{
allTemp = InBox.ToArray();
Debug.Log("array alltemp is");
Debug.Log(string.Join(", ", allTemp));
}
}
Comment