// On trigger stay (used instead of enter since buttons are also checked). void OnTriggerStay(Collider other) { if (other.isTrigger) { // Check to see if collided with cauldron. CauldronController cauldron = other.GetComponent <CauldronController>(); bool cauldronCollision = false; if (cauldron != null) { cauldronCollision = CauldronCheckAndRun(cauldron); } Debug.Log("Colliding with my cauldron: " + cauldronCollision); // Check to see if collided with ingredient IngredientInformation ingredient = other.GetComponent <IngredientInformation>(); bool ingredientCollision = ingredient != null; if (!cauldronCollision && ingredientCollision) { IngredientCheckAndRun(ingredient); } Debug.Log("Colliding with ingredient: " + ingredientCollision); collidingWithInteractiveObject = cauldronCollision || ingredientCollision; // EXPLOSION if (other.gameObject.tag == "Explosion" && playerExploded == false) { print("Oh dear i'm dead"); playerExploded = true; PlayerDeath(); playerExploded = false; } } }
/// <summary> /// Function for checking if the IngredientInformation component is null and assumes a none null value means an ingredient. /// </summary> /// <param name="ingredient">IngredientInformation component.</param> /// <returns>Returns whether the IngredientInformation component is not null.</returns> private bool IngredientCheckAndRun(IngredientInformation ingredient) { // Does the collided object contain an INgredientInformation component? I.e. is it an ingredient if (Input.GetButtonDown("LeftFace" + _mPlayerNumber)) { // Is the left inventory slot occuppied? switch (_leftInventorySlot == null) { // Pick up ingredient. case true: Debug.Log("Slot is empty"); _leftInventorySlot = ingredient.mIngredient; Destroy(ingredient.gameObject); return(true); // Swap ingredient with inventory slot. case false: Debug.Log("Slot is not empty"); InteractiveObject intermediary = _leftInventorySlot; _leftInventorySlot = ingredient.mIngredient; Destroy(ingredient.gameObject); intermediary.SpawnObject(transform.position); return(true); } } else if (Input.GetButtonDown("UpFace" + _mPlayerNumber)) { // Is the up inventory slot occuppied? switch (_upInventorySlot == null) { // Pick up ingredient. case true: _upInventorySlot = ingredient.mIngredient; Destroy(ingredient.gameObject); return(true); // Swap ingredient with inventory slot. case false: InteractiveObject intermediary = _upInventorySlot; _upInventorySlot = ingredient.mIngredient; Destroy(ingredient.gameObject); intermediary.SpawnObject(transform.position); return(true); } } else if (Input.GetButtonDown("RightFace" + _mPlayerNumber)) { // Is the right inventory slot occuppied? switch (_rightInventorySlot == null) { // Pick up ingredient. case true: _rightInventorySlot = ingredient.mIngredient; Destroy(ingredient.gameObject); return(true); // Swap ingredient with inventory slot. case false: InteractiveObject intermediary = _rightInventorySlot; _rightInventorySlot = ingredient.mIngredient; Destroy(ingredient.gameObject); intermediary.SpawnObject(transform.position); return(true); } } else if (Input.GetButtonDown("DownFace" + _mPlayerNumber)) { // Is the down inventory slot occuppied? switch (_downInventorySlot == null) { // Pick up ingredient. case true: _downInventorySlot = ingredient.mIngredient; Destroy(ingredient.gameObject); return(true); // Swap ingredient with inventory slot. case false: InteractiveObject intermediary = _downInventorySlot; _downInventorySlot = ingredient.mIngredient; Destroy(ingredient.gameObject); intermediary.SpawnObject(transform.position); return(true); } } return(false); }