Advertisement
evelynshilosky

InteractableObject - Part 31

Feb 2nd, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class InteractableObject : MonoBehaviour
  6. {
  7.  
  8.     public bool playerInRange;
  9.    
  10.     public string ItemName;
  11.        
  12.     public string GetItemName()
  13.     {
  14.        
  15.         return ItemName;
  16.  
  17.     }
  18.  
  19.  
  20.     void Update()
  21.     {
  22.         if (Input.GetKeyDown(KeyCode.Mouse0) && playerInRange && SelectionManager.Instance.onTarget && SelectionManager.Instance.selectedObject == gameObject) //add item to inventory
  23.         {
  24.  
  25.             //is the inventory is not full
  26.             if (InventorySystem.Instance.CheckSlotsAvailable(1))
  27.             {
  28.  
  29.                 InventorySystem.Instance.AddToInventory(ItemName);
  30.  
  31.                 InventorySystem.Instance.itemsPickedup.Add(gameObject.name);
  32.  
  33.  
  34.                 Destroy(gameObject);
  35.  
  36.             }
  37.             else
  38.             {
  39.                 Debug.Log("Inventory is Full!");
  40.             }
  41.  
  42.  
  43.         }
  44.  
  45.     }
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.     private void OnTriggerEnter(Collider other)
  54.     {
  55.         if (other.CompareTag("Player"))
  56.         {
  57.  
  58.             playerInRange = true;
  59.  
  60.  
  61.         }
  62.  
  63.     }
  64.  
  65.     private void OnTriggerExit(Collider other)
  66.     {
  67.         if (other.CompareTag("Player"))
  68.         {
  69.             playerInRange  = false;
  70.         }
  71.  
  72.     }
  73.  
  74.  
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement