Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        //Moving the waiter for testing purposes
        if (Input.GetKeyDown("x"))
        {
            GeneratePathTo(7, 6);
        }
        //Moving the waiter back
        if (Input.GetKeyDown("c"))
        {
            GeneratePathTo((int)initialPos.x, (int)initialPos.y);
        }

        // Draw our debug line showing the pathfinding!
        // NOTE: This won't appear in the actual game view.
        if (currentPath != null)
        {
            int currNode = 0;

            while (currNode < currentPath.Count - 1)
            {
                Vector3 start = new Vector3(currentPath[currNode].x, 0, currentPath[currNode].y) +
                                new Vector3(0.5f, 0, 0.5f);
                Vector3 end = new Vector3(currentPath[currNode + 1].x, 0, currentPath[currNode + 1].y) +
                              new Vector3(0.5f, 0, 0.5f);

                Debug.DrawLine(start, end, Color.red);

                currNode++;
            }
        }

        if (currentPath != null && currentPath.Count > 0)
        {
            // Have we moved our visible piece close enough to the target tile that we can
            // advance to the next step in our pathfinding?
            if (Vector3.Distance(transform.position, new Vector3(x, 0, y)) < 0.1f)
            {
                AdvancePathing();
            }
        }
        else if ((currentPath == null || currentPath.Count == 0) && (this.x != (int)initialPos.x || this.y != (int)initialPos.y))
        {
            //Make waiter walk back as soon as delivered
            GeneratePathTo((int)initialPos.x, (int)initialPos.y);
            StartCoroutine(orderHandler.DeassignSeat(currentOrder.food, currentOrder.c, currentOrder.custID));
        }
        else if (this.x == (int)initialPos.x && this.y == (int)initialPos.y)
        {
            TakeOrder(orderTried);
        }

        // Smoothly animate towards the correct map tile.
        transform.position = Vector3.Lerp(transform.position, new Vector3(x, 0, y), 5f * Time.deltaTime);
    }