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;
        }
    }