Beispiel #1
0
    void Update()
    {
        // Calls a function to update the UI Text.
        TextUpdate();

        // Calls a function to shoot the raycast.
        RayShoot();

        // Calls a function to manage the recipe book.
        RecipeBookManager();

        // Checks if you press the interact key and that you are looking at an object.
        if (Input.GetKeyDown(KeyCode.E) && collision != null)
        {
            // Checks if you are holding an item and if you are drops it.
            if (holding)
            {
                holding = !holding;
            }
            // Checks if the object you are looking at is a PickUp and if it is picks it up.
            else if (collision.tag == "PickUp")
            {
                pickUp  = collision;
                holding = !holding;
                collision.GetComponent <Rigidbody>().velocity = Vector3.zero;
            }
            // Checks if the object you are looking at is a Crate and if it is takes an item from it.
            else if (collision.tag == "Crate")
            {
                pickUp      = Instantiate(collision.GetComponent <CrateObject>().crateObject);
                pickUp.name = pickUp.name.Replace("(Clone)", "");
                holding     = !holding;
            }
            // Checks if the object you are looking at is a Pot and if so takes the meal in its current state from it.
            else if (collision.tag == "Pot")
            {
                PotController controller = collision.GetComponent <PotController>();

                int index = controller.currentRecipe.meal;
                int state = Mathf.FloorToInt(controller.GetCookingTime());

                mealPrefab = meals[index - recipeBook.foodCount];

                pickUp = Instantiate(mealPrefab);
                pickUp.GetComponent <MealBehaviour>().SetMealBehaviour(index, state);
                holding = !holding;

                controller.Clear();
            }
        }
        // Checks if the current key down is Escape and if so returns to menu.
        else if (Input.GetKeyDown(KeyCode.Escape))
        {
            SceneManager.LoadScene(0);
        }

        // Checks if you are holding and object and if so moves the object infront of the player.
        if (holding)
        {
            pickUp.GetComponent <Transform>().position = transform.position + (transform.forward * 5);
        }
        // Otherwise clears the pickUp variable.
        else
        {
            pickUp = null;
        }
    }
Beispiel #2
0
    // Function to handle updating the UI Text.
    private void TextUpdate()
    {
        // Checks if holding an item and if so defaults to showing drop message.
        if (holding)
        {
            text.text = "Press \"E\" to Drop " + pickUp.name;
        }
        else
        {
            // Checks if there is an object being looked at and that it has a tag.
            if (collision != null && collision.tag != "Untagged")
            {
                // Checks through each of the available tags:
                switch (collision.tag)
                {
                // Checks if the tag is PickUp if so shows pickup message.
                case ("PickUp"):
                    if (!holding)
                    {
                        text.text = "Press \"E\" to Pickup " + collision.name;
                    }
                    break;

                // Checks if the tag is Crate if so shows dispense message.
                case ("Crate"):
                    text.text = "Press \"E\" to Dispense " + collision.GetComponent <CrateObject>().crateFood.name;
                    break;

                // Checks if the tag is Pot is so shows a message depending on the state of the pot.
                case ("Pot"):
                    PotController controller = collision.GetComponent <PotController>();
                    // Checks if the pot is currently cooking if so it shows the collect message with meal name and current state.
                    if (controller.Cooking)
                    {
                        string message = "Press \"E\" to Collect ";

                        if (controller.GetCookingTime() <= 1)
                        {
                            message += recipeBook.foodItems[controller.currentRecipe.meal].name + " (Under Cooked)";
                        }
                        else if (controller.GetCookingTime() <= 2)
                        {
                            message += recipeBook.foodItems[controller.currentRecipe.meal].name + " (Cooked)";
                        }
                        else if (controller.GetCookingTime() <= 3)
                        {
                            message += recipeBook.foodItems[controller.currentRecipe.meal].name + " (Over Cooked)";
                        }
                        else
                        {
                            message += "Burnt Food";
                        }

                        text.text = message;
                    }
                    // Otherwise shows the no recipe messsage.
                    else
                    {
                        text.text = "No Recipe Matched! Add Ingredients.";
                    }
                    break;

                // Checks if the tag is ServingTable and shows the table message.
                case ("ServingTable"):
                    text.text = "Drop Item onto Serving Table to Serve.";
                    break;
                }
                // Show the text object.
                textObject.SetActive(true);
            }
            // Hides the text object.
            else
            {
                textObject.SetActive(false);
            }
        }
    }