97 lines
3.7 KiB
C#
97 lines
3.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using InfallibleCode;
|
|
|
|
namespace TRInventoryUpdatable
|
|
{
|
|
public class KeyInventoryItem : MonoBehaviour, InventoryUpdatable, IUsable
|
|
{
|
|
[Tooltip("This field gets completed automatically when the player acquires a key")]
|
|
public string keyNameInInventory;
|
|
public string keyNameID;
|
|
/* [HideInInspector]*/ public GameObject keyModelForKeyHole;
|
|
|
|
/*[HideInInspector]*/
|
|
public string keyTypeString;
|
|
public bool IsReusable;
|
|
|
|
private void Start()
|
|
{
|
|
keyTypeString = keyType.ToString();
|
|
}
|
|
|
|
public enum KeyType
|
|
{
|
|
DoorKeyType,
|
|
BodyPartKeyType
|
|
}
|
|
|
|
public KeyType keyType = KeyType.DoorKeyType;
|
|
|
|
public void InventoryUpdate()
|
|
{
|
|
InventoryManager.GetInstance().ringInventoryGear.itemName.text = keyNameInInventory;
|
|
InventoryManager.GetInstance().ringInventoryGear.itemDescription.text = "---";
|
|
}
|
|
|
|
public void Use()
|
|
{
|
|
//PlayerHealthManager.GetInstance().UsePill();
|
|
KeysManager.GetInstance().ChangeCurrentlySelectedKeyType(keyTypeString);
|
|
KeysManager.GetInstance().currentlySelectedInventoryKeyNameID = keyNameID;
|
|
KeysManager.GetInstance().currentlySelectedKeyModelForKeyHole = null;
|
|
if (keyModelForKeyHole != null)
|
|
{
|
|
KeysManager.GetInstance().currentlySelectedKeyModelForKeyHole = keyModelForKeyHole;
|
|
}
|
|
//KeysManager.GetInstance().currentlySelectedKeyGo = transform.GetChild(0).gameObject;
|
|
RaycastManager.GetInstance().CheckForInteractableObject();
|
|
if (RaycastManager.GetInstance()._currentHitObject != null)
|
|
{
|
|
if (RaycastManager.GetInstance()._currentHitObject.TryGetComponent(out KeyHole keyhole))
|
|
{
|
|
keyhole.TryUnlockDoor();
|
|
print("Tries to unlock the door");
|
|
}
|
|
else if (RaycastManager.GetInstance()._currentHitObject.TryGetComponent(out StabPuzzle stabPuzzle))
|
|
{
|
|
stabPuzzle.Stab();
|
|
print("Is Stabbing object");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
print("There's no KeyHole script Or Stab script in front of the object you're looking at");
|
|
}
|
|
InventoryManager.GetInstance().CloseInventory();
|
|
|
|
//Remove key from inventory if currently selected door name ID and currently selected inventory key name ID are the SAME.
|
|
if (KeysManager.GetInstance().currentlySelectedKeyAndDoorNameMatch || KeysManager.GetInstance().currentlySelectedJointAndJointHoleMatch)
|
|
{
|
|
StartCoroutine(DestroyKey());
|
|
|
|
print("eleos pia");
|
|
}
|
|
}
|
|
|
|
IEnumerator DestroyKey()
|
|
{
|
|
if (!IsReusable)
|
|
{
|
|
RingInventory.GetInstance().ResetInventoryValuesOnClose();
|
|
|
|
RingInventory.GetInstance().RemoveItemByNameToKeysAndItemsInventory(this.gameObject.name);
|
|
InventoryManager.GetInstance().DeleteTemporarilySavedKeyInventoryItemData(keyNameID);
|
|
}
|
|
else
|
|
{
|
|
RingInventory.GetInstance().ResetInventoryValuesOnClose();
|
|
}
|
|
KeysManager.GetInstance().currentlySelectedKeyAndDoorNameMatch = false;
|
|
KeysManager.GetInstance().currentlySelectedJointAndJointHoleMatch = false;
|
|
yield return new WaitForSecondsRealtime(0.1f);
|
|
Destroy(this.gameObject);
|
|
}
|
|
}
|
|
} |