JojikYT

InteractableChest

Jan 26th, 2023
1,947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | Source Code | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class InteractableChest : Interactable
  6. {
  7.     private Animator animator;
  8.     [Header("Locked Chest Options")]
  9.     public bool isLocked;
  10.     public string chestID;
  11.     public bool isOpen;
  12.  
  13.     public override void Start()
  14.     {
  15.         base.Start();
  16.         animator = GetComponent<Animator>();
  17.         isOpen = false;
  18.     }
  19.  
  20.     protected override void Interaction()
  21.     {
  22.         base.Interaction();
  23.  
  24.         if (!isLocked)
  25.         {
  26.             if (!isOpen)
  27.             {
  28.                 OpenChest();
  29.                 print("Opening the chest");
  30.                
  31.             }
  32.             else
  33.             {
  34.                 CloseChest();
  35.                 print("Closing the chest");
  36.             }
  37.            
  38.         }
  39.         else
  40.         {
  41.             /*
  42.             Inventory inventory = player.GetComponent<Inventory>();
  43.             List<Item> items = inventory.GetItems(Resources.Load<Item>("heavyChestKey"));
  44.             foreach (Item item in items)
  45.             {
  46.                 if (((KeyItem)item).keyID == chestID)
  47.                 {
  48.                     print("unlocked");
  49.                     isLocked = false;
  50.                     Events.RemoveInventoryItem(item, 1);
  51.                     OpenChest();
  52.                 }
  53.                 else
  54.                 {
  55.                     print("locked & wrong key");
  56.                 }
  57.             }
  58.             */
  59.  
  60.         }
  61.     }
  62.  
  63.  
  64.     void CloseChest()
  65.     {
  66.         //Events.ShowLoot(false);
  67.         animator.SetTrigger("CloseChest");
  68.         isOpen = !isOpen;
  69.     }
  70.  
  71.     void OpenChest()
  72.     {
  73.         //GetComponent<ItemContainer>().SetLoot();
  74.         //Events.ShowLoot(true);
  75.         animator.SetTrigger("OpenChest");
  76.         isOpen = !isOpen;
  77.  
  78.         //Events.OnShowLoot += TriggerChest;
  79.     }
  80.     /*
  81.     void TriggerChest(bool openChest)
  82.     {
  83.         if (openChest)
  84.         {
  85.             GetComponent<ItemContainer>().SetLoot();
  86.             Events.ShowLoot(true);
  87.             animator.SetTrigger("OpenChest");
  88.             isOpen = !isOpen;
  89.         }
  90.         else
  91.         {
  92.             GetComponent<ItemContainer>().ResetLoot();
  93.             animator.SetTrigger("CloseChest");
  94.             isOpen = !isOpen;
  95.             Events.OnShowLoot -= TriggerChest;
  96.         }
  97.     }
  98.     */
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment