| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using UnityEngine; |
| | | 4 | | using UnityEngine.Events; |
| | | 5 | | |
| | | 6 | | public class Usable : Inspectable { |
| | | 7 | | public Item useItem; |
| | | 8 | | public string successMessage, failureMessage; |
| | | 9 | | public UnityEvent dispatch; // Callback |
| | | 10 | | |
| | 0 | 11 | | public void Use(Inventory inv) { |
| | | 12 | | // Check if item matches what’s expected |
| | 0 | 13 | | if (inv.SelectedItem == null) { |
| | 0 | 14 | | Inspect(); // Item is not usable |
| | 0 | 15 | | } else if (inv.SelectedItem == useItem) { |
| | 0 | 16 | | Inspect(successMessage); |
| | 0 | 17 | | inv.RemoveItem(useItem); |
| | 0 | 18 | | if (dispatch != null) dispatch.Invoke(); |
| | 0 | 19 | | } else { |
| | 0 | 20 | | Inspect(failureMessage); |
| | 0 | 21 | | } |
| | 0 | 22 | | } |
| | | 23 | | } |
| | | 24 | | |