Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class InteractableObject : MonoBehaviour
- {
- public bool playerInRange;
- public string ItemName;
- [SerializeField] float detectionRange = 10f;
- public string GetItemName()
- {
- return ItemName;
- }
- void Update()
- {
- float distance = Vector3.Distance(PlayerState.Instance.playerBody.transform.position, transform.position);
- if (distance < detectionRange)
- {
- playerInRange = true;
- }
- else
- {
- playerInRange = false;
- }
- if (Input.GetKeyDown(KeyCode.Mouse0) && playerInRange && SelectionManager.Instance.onTarget && SelectionManager.Instance.selectedObject == gameObject) //add item to inventory
- {
- //is the inventory is not full
- if (InventorySystem.Instance.CheckSlotsAvailable(1))
- {
- InventorySystem.Instance.AddToInventory(ItemName);
- InventorySystem.Instance.itemsPickedup.Add(gameObject.name);
- Destroy(gameObject);
- }
- else
- {
- Debug.Log("Inventory is Full!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement