evelynshilosky

StorageInteractable - Part 6.3.4

May 2nd, 2025
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class StorageInteractable : InteractableObject
  4. {
  5.     public Transform storageHolder;
  6.  
  7.     private void Awake()
  8.     {
  9.         item = GetComponent<Item>();
  10.         if (item == null)
  11.         {
  12.             Debug.LogError("StorageInteractable requires an Item component on the same GameObject.");
  13.             enabled = false;
  14.         }
  15.     }
  16.  
  17.     private void Start()
  18.     {
  19.         if (item != null && storageHolder != null)
  20.         {
  21.             StorageSystem.Instance.InitializeStorage(item);
  22.             StorageSystem.Instance.RegisterStorage(item, storageHolder);
  23.  
  24.             // Automatically add a blanket to backpack inventories
  25.             if (item.isBackpack && UIManager.Instance.blanketPrefab != null)
  26.             {
  27.                 Item blanketItem = Instantiate(UIManager.Instance.blanketPrefab).GetComponent<Item>();
  28.                 StorageSystem.Instance.AddToStorage(item, blanketItem);
  29.             }
  30.         }
  31.     }
  32.  
  33.  
  34.     public override void Interact(PlayerMovement playerMovement, bool isRightClick)
  35.     {
  36.         if (isRightClick)
  37.         {
  38.             UIManager.Instance.ShowInventoryPrompt(item);
  39.         }
  40.         else
  41.         {
  42.             base.Interact(playerMovement, isRightClick);
  43.         }
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment