3DSurvivalGame / Assets /Scripts /InteractableObject.cs
doc2txt's picture
1
3497d64
raw
history blame
1.11 kB
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) {
// Debug.Log("Item added to inventory");
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;
}
}
}