68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System.IO;
|
|
|
|
namespace InfallibleCode
|
|
{
|
|
public class Battery : MonoBehaviour, IInteractable
|
|
{
|
|
bool BatteryCollected;
|
|
|
|
// Unique ID for this battery
|
|
public string uniqueID;
|
|
|
|
public void GenerateUniqueID()
|
|
{
|
|
// Generate a unique ID (you can customize this logic based on your requirements)
|
|
uniqueID = System.Guid.NewGuid().ToString();
|
|
Debug.Log("Generated Unique ID: " + uniqueID);
|
|
}
|
|
|
|
public void CollectBattery() //Collects batteries.
|
|
{
|
|
if (BatteryManager.GetInstance().CanCarryBatteries && !BatteryCollected)
|
|
{
|
|
//if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton0))
|
|
//{
|
|
BatteryCollected = true;
|
|
BatteryManager.GetInstance().batteriesCollected += 1;
|
|
AudioManager.GetInstance().PickUpItemSoundPlay();
|
|
|
|
//Add to ring inventory the new item if it doesn't exist.
|
|
if (InventoryManager.GetInstance().batteryOnRingInventory.activeSelf == false)
|
|
{
|
|
RingInventory.GetInstance().AddItemToKeysAndItemsInventory(InventoryManager.GetInstance().batteryOnRingInventory.transform);
|
|
print("Is reconstructing inventory");
|
|
InventoryManager.GetInstance().batteryOnRingInventory.SetActive(true);
|
|
}
|
|
|
|
//InventoryManager.GetInstance().SaveTemporarilyObtainedItemsData(gameObject.name);
|
|
InventoryManager.GetInstance().SaveTemporarilySavedBatteriesInventoryItemsData(gameObject.name, uniqueID);
|
|
|
|
StartCoroutine(DestroyBattery());
|
|
//}
|
|
}
|
|
else //If you can't carry any more batteries because your inventory is full:
|
|
{
|
|
//if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton0))
|
|
//{
|
|
print("You can't carry any more batteries INVENTORY FULL!");
|
|
//}
|
|
}
|
|
}
|
|
|
|
IEnumerator DestroyBattery()
|
|
{
|
|
yield return new WaitForSeconds(0.1f);
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public void Interact()
|
|
{
|
|
CollectBattery();
|
|
}
|
|
}
|
|
|
|
}
|