Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector2      mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D hit      = Physics2D.Raycast(mousePos, Vector2.up);
            if (hit.collider)
            {
                Vector3 loc = hit.collider.transform.position;
                if (hit.collider.tag == "ingredients")
                {
                    hit.collider.GetComponent <IngredientBoxScript>().OnClick();
                    m_locations.Enqueue(new Vector3(loc.x, loc.y + 2, loc.z));
                }
                else if (hit.collider.tag == "customer")
                {
                    hit.collider.GetComponent <Customer>().OnClick();
                }
            }
        }
        //setting the player to move if there is only one location to go to
        if (!m_needsToMove && m_locations.Count >= 1)
        {
            m_nextLocation = m_locations.Dequeue();
            m_needsToMove  = true;
        }

        //if enough time has passed, put the next item in the queue into the player's hand
        if (!m_needsToMove && m_playerQueue.Count > 0)
        {
            if (m_locations.Count > 0)
            {
                m_nextLocation = m_locations.Dequeue();
                m_needsToMove  = true;
            }
            //putting the ingredient into the player's hand
            if (m_playerQueue.Peek().GetType() == typeof(Ingredients))
            {
                m_itemsInHand.Add((Ingredients)m_playerQueue.Dequeue());
            }
            //"using" the kitchen utensil.  must check if the recipe exists
            else if (m_playerQueue.Peek().GetType() == typeof(CookingUtensilScript))
            {
                CookingUtensilScript tool = (CookingUtensilScript)m_playerQueue.Dequeue();

                //if there is a plate for us to pick up.
                if (tool.HasPlate())
                {
                    //can only pick up the plate if there is no other plate in our hand
                    if (m_plateInHand == null)
                    {
                        //we picked up a plate
                        ChangePlateInHand(tool.PickUpPlate());
                    }
                }
                //if no plate, we will place the recipe as long as we have items to cook and there is nothing on the stove
                else if (m_itemsInHand.Count > 0)
                {
                    Recipe r = GetRecipe(m_itemsInHand.ToArray(), tool.utensil.utensil);

                    //either putting a recipe in or finding what we should get from clicking on the utensil
                    tool.Loading(PlayerData.GetFoodSprite(r.recipeName), r);

                    m_itemsInHand.Clear();
                }
            }
            //clicked on a customer
            else
            {
                Customer c = CustomerGenerator.GetCustomer((int)m_playerQueue.Dequeue());
                GivePlateToCustomer(c.GetOrder(), c.GetCustomerNumber());
            }
        }

        if (m_needsToMove)
        {
            Vector3 catPos = transform.position;
            if (catPos == m_nextLocation)
            {
                m_needsToMove = false;
            }
            else
            {
                transform.position = Vector3.MoveTowards(catPos, m_nextLocation, 0.2f);
            }
        }
    }