protected override void HandleInteraction(PlayerController playerInteracting) { // If theere is already a player chopping items on the board, then do nothing if (_activeChoppingState != null) { return; } // If the player has any items in hand, then the player can't chop items on a board if (playerInteracting.PlayerHand.HasAnyItemInHand()) { return; } // If all the items on the board aren't choppable, then the player can't chop items on the board Choppable choppableItem = transform.GetComponentInChildren <Choppable>(); if (choppableItemOnBoard == null) { return; } // If the choppable item on the board is already chopped, then the player can't chop items on the board else if (choppableItem.ChopComplete) { return; } // Otherwise, let's get chopping // Create a new player state with the player that's interacting with this chopping board // and the choppable item to chop _activeChoppingState = new ChoppingState(playerInteracting, choppableItem, OnChoppingEnded); // Assign the new chopping state to the player playerInteracting.SetPlayerState(_activeChoppingState); // Call the on chop starting event OnChopStarting.Invoke(choppableItem); }
private void OnChoppingEnded(Choppable itemChopped) { Debug.Log("End of chop"); // Call the on chop ending event OnChopEnding.Invoke(itemChopped); if (itemChopped.ChopComplete) { Debug.Log("Item chop complete"); FoodGameObject choppedResult = Instantiate(itemChopped.ChoppedIngredient.IngredientPrefab, itemChopped.transform.position, itemChopped.transform.rotation); choppedResult.transform.parent = itemChopped.transform.parent; choppedResult.GetHoldableItemComponent().ToggleRigidBodyKinematic(true); OnChoppableItemUnboarded.Invoke(itemChopped); Destroy(itemChopped.gameObject); } _activeChoppingState = null; }