|
|
|
|
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public class InteractableObject : MonoBehaviour |
|
{ |
|
public string ItemName; |
|
|
|
public bool playerInRanger; |
|
|
|
public string GetItemName() |
|
{ |
|
return ItemName; |
|
} |
|
|
|
private void Update() { |
|
if (Input.GetKeyDown(KeyCode.Mouse0)&& playerInRanger |
|
&& SelectionManager.Instance.onTarget |
|
&& SelectionManager.Instance.selectedObject == gameObject) { |
|
|
|
if (InventorySystem.Instance.CheckSlotsAvailable(1)) { |
|
InventorySystem.Instance.AddToInventory(ItemName); |
|
Destroy(gameObject); |
|
} else { |
|
Debug.Log("Inventory Full"); |
|
} |
|
} |
|
} |
|
|
|
private void OnTriggerEnter(Collider other) |
|
{ |
|
if (other.CompareTag("Player")) |
|
{ |
|
playerInRanger = true; |
|
} |
|
} |
|
|
|
private void OnTriggerExit(Collider other) |
|
{ |
|
if (other.CompareTag("Player")) |
|
{ |
|
playerInRanger = false; |
|
} |
|
} |
|
} |