コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        // Don't update if the game is over
        if (!CustomerSpawn.GameIsOver())
        {
            // Decrease timer at rate determined by customer satisfaction
            timer -= Time.deltaTime * anger;

            // When timer elapses, customer leaves and deducts points in dissatisfaction
            if (timer <= 0.0)
            {
                if (anger == 1.0)
                {
                    P1Movement.ScorePenalty(BASE_PENALTY * numIngredients);
                    P2Movement.ScorePenalty(BASE_PENALTY * numIngredients);
                }

                // Determine which player(s) deserve(s) the penalty
                else
                {
                    if (aScale > 0)
                    {
                        P1Movement.ScorePenalty(BASE_PENALTY * numIngredients * 2);
                    }
                    else if (aScale < 0)
                    {
                        P2Movement.ScorePenalty(BASE_PENALTY * numIngredients * 2);
                    }
                    else
                    {
                        P1Movement.ScorePenalty(BASE_PENALTY * numIngredients * 2);
                        P2Movement.ScorePenalty(BASE_PENALTY * numIngredients * 2);
                    }
                }
                CustomerSpawn.SetOccupied(custID, false);
                Destroy(gameObject);
            }
        }
    }
コード例 #2
0
    // Checks proximity with stations and interacts with them
    void CheckObjects(Vector3 pos)
    {
        // Cutting board: hold still and chop a vegetable if player is holding one
        if (Vector3.Distance(pos, chopBoard.transform.position) <= 1.5)
        {
            if (leftHandOccupied && leftHandVeggie.tag != "Salad")
            {
                boardVeggie = Instantiate(leftHandVeggie) as GameObject;
                Vector3 surface = chopBoard.transform.position;
                surface.x -= 0.25f;
                surface.z -= 0.75f;
                boardVeggie.transform.position = surface;
                leftHandOccupied = false;
                Destroy(leftHandVeggie);

                // Move right hand veggie to occupy left hand for next interaction
                if (rightHandOccupied)
                {
                    leftHandVeggie = Instantiate(rightHandVeggie) as GameObject;
                    if (rightHandVeggie.tag == "Salad")
                    {
                        rightHandVeggie.GetComponent <SaladType>().MoveSalad(leftHandVeggie);
                        leftHandVeggie.GetComponent <SaladType>().SetP1Owns(true);
                    }
                    leftHandOccupied  = true;
                    rightHandOccupied = false;
                    Destroy(rightHandVeggie);
                }

                // Start timer for chopping veggie
                canMove   = false;
                moveTimer = COOLDOWN;
            }
            else if (chopBoardOccupied)
            {
                if (!leftHandOccupied)
                {
                    leftHandVeggie = Instantiate(boardSalad) as GameObject;
                    boardSalad.GetComponent <SaladType>().MoveSalad(leftHandVeggie);
                    leftHandVeggie.GetComponent <SaladType>().SetP1Owns(true);
                    leftHandOccupied  = true;
                    chopBoardOccupied = false;
                    Destroy(boardSalad);
                }
                else if (!rightHandOccupied)
                {
                    rightHandVeggie = Instantiate(boardSalad) as GameObject;
                    boardSalad.GetComponent <SaladType>().MoveSalad(rightHandVeggie);
                    rightHandVeggie.GetComponent <SaladType>().SetP1Owns(true);
                    rightHandOccupied = true;
                    chopBoardOccupied = false;
                    Destroy(boardSalad);
                }
            }
        }

        // Spare plate: leave a veggie you're holding if empty, pick veggie up if full
        if (Vector3.Distance(pos, sparePlate.transform.position) <= 1.4)
        {
            if (leftHandOccupied && !sparePlateOccupied)
            {
                plateVeggie = Instantiate(leftHandVeggie) as GameObject;
                if (leftHandVeggie.tag == "Salad")
                {
                    leftHandVeggie.GetComponent <SaladType>().MoveSalad(plateVeggie);
                    plateVeggie.GetComponent <SaladType>().SetP1Owns(true);
                }
                Vector3 surface = sparePlate.transform.position;
                surface.z -= 0.25f;
                plateVeggie.transform.position = surface;
                sparePlateOccupied             = true;
                leftHandOccupied = false;
                Destroy(leftHandVeggie);

                // Move right hand veggie to occupy left hand for next interaction
                if (rightHandOccupied)
                {
                    leftHandVeggie = Instantiate(rightHandVeggie) as GameObject;
                    if (rightHandVeggie.tag == "Salad")
                    {
                        rightHandVeggie.GetComponent <SaladType>().MoveSalad(leftHandVeggie);
                        leftHandVeggie.GetComponent <SaladType>().SetP1Owns(true);
                    }
                    leftHandOccupied  = true;
                    rightHandOccupied = false;
                    Destroy(rightHandVeggie);
                }
            }
            else if (sparePlateOccupied)
            {
                if (!leftHandOccupied)
                {
                    leftHandVeggie = Instantiate(plateVeggie) as GameObject;
                    if (plateVeggie.tag == "Salad")
                    {
                        plateVeggie.GetComponent <SaladType>().MoveSalad(leftHandVeggie);
                        leftHandVeggie.GetComponent <SaladType>().SetP1Owns(true);
                    }
                    leftHandOccupied   = true;
                    sparePlateOccupied = false;
                    Destroy(plateVeggie);
                }
                else if (!rightHandOccupied)
                {
                    rightHandVeggie = Instantiate(plateVeggie) as GameObject;
                    if (plateVeggie.tag == "Salad")
                    {
                        plateVeggie.GetComponent <SaladType>().MoveSalad(rightHandVeggie);
                        rightHandVeggie.GetComponent <SaladType>().SetP1Owns(true);
                    }
                    rightHandOccupied  = true;
                    sparePlateOccupied = false;
                    Destroy(plateVeggie);
                }
            }
        }

        // Trash can: discard whatever you're holding in your left hand
        if (Vector3.Distance(pos, trash.transform.position) <= 1.35)
        {
            if (leftHandOccupied)
            {
                if (leftHandVeggie.tag == "Salad")
                {
                    score -= leftHandVeggie.GetComponent <SaladType>().GetNumIngredients() * 5;
                }
                else
                {
                    score--;
                }
                leftHandOccupied = false;
                Destroy(leftHandVeggie);

                // Move right hand veggie to occupy left hand for next interaction
                if (rightHandOccupied)
                {
                    leftHandVeggie = Instantiate(rightHandVeggie) as GameObject;
                    if (rightHandVeggie.tag == "Salad")
                    {
                        rightHandVeggie.GetComponent <SaladType>().MoveSalad(leftHandVeggie);
                        leftHandVeggie.GetComponent <SaladType>().SetP1Owns(true);
                    }
                    leftHandOccupied  = true;
                    rightHandOccupied = false;
                    Destroy(rightHandVeggie);
                }
            }
        }

        // Veggies: grab an instance of the veggie you're in front of if you can carry it
        if (Vector3.Distance(pos, veggie1.transform.position) <= 1.25)
        {
            if (!leftHandOccupied)
            {
                leftHandVeggie   = Instantiate(vLettuce) as GameObject;
                leftHandOccupied = true;
            }
            else if (!rightHandOccupied)
            {
                rightHandVeggie   = Instantiate(vLettuce) as GameObject;
                rightHandOccupied = true;
            }
        }
        if (Vector3.Distance(pos, veggie2.transform.position) <= 1.25)
        {
            if (!leftHandOccupied)
            {
                leftHandVeggie   = Instantiate(vTomato) as GameObject;
                leftHandOccupied = true;
            }
            else if (!rightHandOccupied)
            {
                rightHandVeggie   = Instantiate(vTomato) as GameObject;
                rightHandOccupied = true;
            }
        }
        if (Vector3.Distance(pos, veggie3.transform.position) <= 1.25)
        {
            if (!leftHandOccupied)
            {
                leftHandVeggie   = Instantiate(vCarrot) as GameObject;
                leftHandOccupied = true;
            }
            else if (!rightHandOccupied)
            {
                rightHandVeggie   = Instantiate(vCarrot) as GameObject;
                rightHandOccupied = true;
            }
        }
        if (Vector3.Distance(pos, veggie4.transform.position) <= 1.25)
        {
            if (!leftHandOccupied)
            {
                leftHandVeggie   = Instantiate(vCheese) as GameObject;
                leftHandOccupied = true;
            }
            else if (!rightHandOccupied)
            {
                rightHandVeggie   = Instantiate(vCheese) as GameObject;
                rightHandOccupied = true;
            }
        }
        if (Vector3.Distance(pos, veggie5.transform.position) <= 1.25)
        {
            if (!leftHandOccupied)
            {
                leftHandVeggie   = Instantiate(vTurnip) as GameObject;
                leftHandOccupied = true;
            }
            else if (!rightHandOccupied)
            {
                rightHandVeggie   = Instantiate(vTurnip) as GameObject;
                rightHandOccupied = true;
            }
        }
        if (Vector3.Distance(pos, veggie6.transform.position) <= 1.25)
        {
            if (!leftHandOccupied)
            {
                leftHandVeggie   = Instantiate(vCaper) as GameObject;
                leftHandOccupied = true;
            }
            else if (!rightHandOccupied)
            {
                rightHandVeggie   = Instantiate(vCaper) as GameObject;
                rightHandOccupied = true;
            }
        }

        // Customers: give salad to customer if both are present, compare salad and order to see if they match
        if (Vector3.Distance(pos, order1.transform.position) <= 1.4)
        {
            if (leftHandOccupied && leftHandVeggie.tag == "Salad" && service.GetComponent <CustomerSpawn>().GetOccupied1())
            {
                GameObject customer = GameObject.FindWithTag("Cust1");
                int        ltc      = customer.GetComponent <CustomerOrder>().GetNumLettuce();
                int        tmt      = customer.GetComponent <CustomerOrder>().GetNumTomato();
                int        crt      = customer.GetComponent <CustomerOrder>().GetNumCarrot();
                int        chs      = customer.GetComponent <CustomerOrder>().GetNumCheese();
                int        tnp      = customer.GetComponent <CustomerOrder>().GetNumTurnip();
                int        cpr      = customer.GetComponent <CustomerOrder>().GetNumCaper();
                if (leftHandVeggie.GetComponent <SaladType>().CheckSalad(ltc, tmt, crt, chs, tnp, cpr))
                {
                    CustomerSpawn.SetOccupied(1, false);
                    score += leftHandVeggie.GetComponent <SaladType>().GetNumIngredients() * 10;
                    Destroy(customer);
                }
                else
                {
                    customer.GetComponent <CustomerOrder>().MakeAngry(true);
                }
                leftHandOccupied = false;
                Destroy(leftHandVeggie);

                // Move right hand veggie to occupy left hand for next interaction
                if (rightHandOccupied)
                {
                    leftHandVeggie = Instantiate(rightHandVeggie) as GameObject;
                    if (rightHandVeggie.tag == "Salad")
                    {
                        rightHandVeggie.GetComponent <SaladType>().MoveSalad(leftHandVeggie);
                        leftHandVeggie.GetComponent <SaladType>().SetP1Owns(true);
                    }
                    leftHandOccupied  = true;
                    rightHandOccupied = false;
                    Destroy(rightHandVeggie);
                }
            }
        }
        if (Vector3.Distance(pos, order2.transform.position) <= 1.4)
        {
            if (leftHandOccupied && leftHandVeggie.tag == "Salad" && service.GetComponent <CustomerSpawn>().GetOccupied2())
            {
                GameObject customer = GameObject.FindWithTag("Cust2");
                int        ltc      = customer.GetComponent <CustomerOrder>().GetNumLettuce();
                int        tmt      = customer.GetComponent <CustomerOrder>().GetNumTomato();
                int        crt      = customer.GetComponent <CustomerOrder>().GetNumCarrot();
                int        chs      = customer.GetComponent <CustomerOrder>().GetNumCheese();
                int        tnp      = customer.GetComponent <CustomerOrder>().GetNumTurnip();
                int        cpr      = customer.GetComponent <CustomerOrder>().GetNumCaper();
                if (leftHandVeggie.GetComponent <SaladType>().CheckSalad(ltc, tmt, crt, chs, tnp, cpr))
                {
                    CustomerSpawn.SetOccupied(2, false);
                    score += leftHandVeggie.GetComponent <SaladType>().GetNumIngredients() * 10;
                    Destroy(customer);
                }
                else
                {
                    customer.GetComponent <CustomerOrder>().MakeAngry(true);
                }
                leftHandOccupied = false;
                Destroy(leftHandVeggie);

                // Move right hand veggie to occupy left hand for next interaction
                if (rightHandOccupied)
                {
                    leftHandVeggie = Instantiate(rightHandVeggie) as GameObject;
                    if (rightHandVeggie.tag == "Salad")
                    {
                        rightHandVeggie.GetComponent <SaladType>().MoveSalad(leftHandVeggie);
                        leftHandVeggie.GetComponent <SaladType>().SetP1Owns(true);
                    }
                    leftHandOccupied  = true;
                    rightHandOccupied = false;
                    Destroy(rightHandVeggie);
                }
            }
        }
        if (Vector3.Distance(pos, order3.transform.position) <= 1.4)
        {
            if (leftHandOccupied && leftHandVeggie.tag == "Salad" && service.GetComponent <CustomerSpawn>().GetOccupied3())
            {
                GameObject customer = GameObject.FindWithTag("Cust3");
                int        ltc      = customer.GetComponent <CustomerOrder>().GetNumLettuce();
                int        tmt      = customer.GetComponent <CustomerOrder>().GetNumTomato();
                int        crt      = customer.GetComponent <CustomerOrder>().GetNumCarrot();
                int        chs      = customer.GetComponent <CustomerOrder>().GetNumCheese();
                int        tnp      = customer.GetComponent <CustomerOrder>().GetNumTurnip();
                int        cpr      = customer.GetComponent <CustomerOrder>().GetNumCaper();
                if (leftHandVeggie.GetComponent <SaladType>().CheckSalad(ltc, tmt, crt, chs, tnp, cpr))
                {
                    CustomerSpawn.SetOccupied(3, false);
                    score += leftHandVeggie.GetComponent <SaladType>().GetNumIngredients() * 10;
                    Destroy(customer);
                }
                else
                {
                    customer.GetComponent <CustomerOrder>().MakeAngry(true);
                }
                leftHandOccupied = false;
                Destroy(leftHandVeggie);

                // Move right hand veggie to occupy left hand for next interaction
                if (rightHandOccupied)
                {
                    leftHandVeggie = Instantiate(rightHandVeggie) as GameObject;
                    if (rightHandVeggie.tag == "Salad")
                    {
                        rightHandVeggie.GetComponent <SaladType>().MoveSalad(leftHandVeggie);
                        leftHandVeggie.GetComponent <SaladType>().SetP1Owns(true);
                    }
                    leftHandOccupied  = true;
                    rightHandOccupied = false;
                    Destroy(rightHandVeggie);
                }
            }
        }
        if (Vector3.Distance(pos, order4.transform.position) <= 1.4)
        {
            if (leftHandOccupied && leftHandVeggie.tag == "Salad" && service.GetComponent <CustomerSpawn>().GetOccupied4())
            {
                GameObject customer = GameObject.FindWithTag("Cust4");
                int        ltc      = customer.GetComponent <CustomerOrder>().GetNumLettuce();
                int        tmt      = customer.GetComponent <CustomerOrder>().GetNumTomato();
                int        crt      = customer.GetComponent <CustomerOrder>().GetNumCarrot();
                int        chs      = customer.GetComponent <CustomerOrder>().GetNumCheese();
                int        tnp      = customer.GetComponent <CustomerOrder>().GetNumTurnip();
                int        cpr      = customer.GetComponent <CustomerOrder>().GetNumCaper();
                if (leftHandVeggie.GetComponent <SaladType>().CheckSalad(ltc, tmt, crt, chs, tnp, cpr))
                {
                    CustomerSpawn.SetOccupied(4, false);
                    score += leftHandVeggie.GetComponent <SaladType>().GetNumIngredients() * 10;
                    Destroy(customer);
                }
                else
                {
                    customer.GetComponent <CustomerOrder>().MakeAngry(true);
                }
                leftHandOccupied = false;
                Destroy(leftHandVeggie);

                // Move right hand veggie to occupy left hand for next interaction
                if (rightHandOccupied)
                {
                    leftHandVeggie = Instantiate(rightHandVeggie) as GameObject;
                    if (rightHandVeggie.tag == "Salad")
                    {
                        rightHandVeggie.GetComponent <SaladType>().MoveSalad(leftHandVeggie);
                        leftHandVeggie.GetComponent <SaladType>().SetP1Owns(true);
                    }
                    leftHandOccupied  = true;
                    rightHandOccupied = false;
                    Destroy(rightHandVeggie);
                }
            }
        }
        if (Vector3.Distance(pos, order5.transform.position) <= 1.4)
        {
            if (leftHandOccupied && leftHandVeggie.tag == "Salad" && service.GetComponent <CustomerSpawn>().GetOccupied5())
            {
                GameObject customer = GameObject.FindWithTag("Cust5");
                int        ltc      = customer.GetComponent <CustomerOrder>().GetNumLettuce();
                int        tmt      = customer.GetComponent <CustomerOrder>().GetNumTomato();
                int        crt      = customer.GetComponent <CustomerOrder>().GetNumCarrot();
                int        chs      = customer.GetComponent <CustomerOrder>().GetNumCheese();
                int        tnp      = customer.GetComponent <CustomerOrder>().GetNumTurnip();
                int        cpr      = customer.GetComponent <CustomerOrder>().GetNumCaper();
                if (leftHandVeggie.GetComponent <SaladType>().CheckSalad(ltc, tmt, crt, chs, tnp, cpr))
                {
                    CustomerSpawn.SetOccupied(5, false);
                    score += leftHandVeggie.GetComponent <SaladType>().GetNumIngredients() * 10;
                    Destroy(customer);
                }
                else
                {
                    customer.GetComponent <CustomerOrder>().MakeAngry(true);
                }
                leftHandOccupied = false;
                Destroy(leftHandVeggie);

                // Move right hand veggie to occupy left hand for next interaction
                if (rightHandOccupied)
                {
                    leftHandVeggie = Instantiate(rightHandVeggie) as GameObject;
                    if (rightHandVeggie.tag == "Salad")
                    {
                        rightHandVeggie.GetComponent <SaladType>().MoveSalad(leftHandVeggie);
                        leftHandVeggie.GetComponent <SaladType>().SetP1Owns(true);
                    }
                    leftHandOccupied  = true;
                    rightHandOccupied = false;
                    Destroy(rightHandVeggie);
                }
            }
        }
    }