Advertisement
evelynshilosky

InteractableObject - Part 26

Nov 17th, 2023 (edited)
146
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.     private void OnTriggerEnter(Collider other)
  49.     {
  50.         if (other.CompareTag("Player"))
  51.         {
  52.  
  53.             playerInRange = true;
  54.  
  55.  
  56.         }
  57.  
  58.     }
  59.  
  60.  
  61.  
  62.  
  63.     private void OnTriggerExit(Collider other)
  64.     {
  65.         if (other.CompareTag("Player"))
  66.         {
  67.             playerInRange  = false;
  68.         }
  69.  
  70.     }
  71.  
  72.  
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement