2022-04-19 16:18:30 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2022-05-29 12:33:43 +02:00
|
|
|
using System;
|
2022-04-19 16:18:30 +02:00
|
|
|
|
2022-05-15 18:54:59 +02:00
|
|
|
public class PickableController : MonoBehaviour
|
2022-04-19 16:18:30 +02:00
|
|
|
{
|
2022-12-06 01:58:32 +01:00
|
|
|
public Item item;
|
2023-01-06 03:44:07 +01:00
|
|
|
public string itemName;
|
2022-10-02 18:45:58 +02:00
|
|
|
//public string name2; //TODO Clear here
|
2022-06-15 19:54:44 +02:00
|
|
|
public bool triggered;
|
|
|
|
public int isPicked;
|
2022-05-15 18:54:59 +02:00
|
|
|
|
2022-06-17 22:22:19 +02:00
|
|
|
public int HandleIndexInScelenObjectList;
|
|
|
|
|
2022-12-06 01:58:32 +01:00
|
|
|
public void Awake()
|
|
|
|
{
|
2023-01-06 03:44:07 +01:00
|
|
|
|
2022-12-06 01:58:32 +01:00
|
|
|
//item.Name = gameObject.name;
|
2023-01-06 03:44:07 +01:00
|
|
|
|
|
|
|
// IT DONT WORK - equippable item with the same name isn't finding
|
|
|
|
/* Debug.Log("Items/" + itemName);
|
|
|
|
item = Resources.Load<Item>("Items/" + itemName);
|
|
|
|
|
|
|
|
if (item = null)
|
|
|
|
{
|
|
|
|
item = Resources.Load<EquippableItem>("Items/" + itemName);
|
|
|
|
}*/
|
2022-12-06 01:58:32 +01:00
|
|
|
}
|
|
|
|
|
2022-05-15 18:54:59 +02:00
|
|
|
public void Start()
|
|
|
|
{
|
2022-06-17 22:22:19 +02:00
|
|
|
// if object after beeing created by Instaniate() gets "Clone)" postfix, EquippableItem.name gets this
|
2023-01-06 03:44:07 +01:00
|
|
|
|
2022-06-17 22:22:19 +02:00
|
|
|
// if (PlayerPrefs.GetInt("continued") == 1)
|
|
|
|
// {
|
|
|
|
// isPicked = PlayerPrefs.GetInt(name2);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// isPicked = PlayerPrefs.GetInt(name);
|
|
|
|
// }
|
2023-01-06 03:44:07 +01:00
|
|
|
//name = item.ItemModel.name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isPicked == 1)
|
2022-06-02 18:32:18 +02:00
|
|
|
{
|
2022-06-17 22:22:19 +02:00
|
|
|
//gameObject.SetActive(false);
|
|
|
|
Destroy(gameObject);
|
2022-06-02 18:32:18 +02:00
|
|
|
}
|
2022-05-15 18:54:59 +02:00
|
|
|
}
|
|
|
|
|
2022-06-15 19:54:44 +02:00
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if(triggered)
|
|
|
|
{
|
|
|
|
if (Input.GetKeyDown(KeyCode.E))
|
|
|
|
{
|
2022-11-24 03:03:30 +01:00
|
|
|
if(!InventoryUIManager.Instance.IsFull())
|
2022-06-19 14:38:22 +02:00
|
|
|
{
|
2023-01-06 03:44:07 +01:00
|
|
|
var castedItem = this.item as EquippableItem;
|
|
|
|
|
|
|
|
if(castedItem == null)
|
|
|
|
InventoryUIManager.Instance.Add(new EquippableItem(this.item));
|
|
|
|
else
|
|
|
|
InventoryUIManager.Instance.Add(new EquippableItem(castedItem));
|
2022-11-27 21:28:55 +01:00
|
|
|
|
2023-01-06 03:44:07 +01:00
|
|
|
if (InventoryUIManager.Instance.GetPanelStatus())
|
2022-11-27 21:28:55 +01:00
|
|
|
GameObject.FindObjectOfType<InventoryPanelController>().BuildPanelContent(InventoryUIManager.Instance.GetList());
|
|
|
|
|
2022-06-19 14:38:22 +02:00
|
|
|
isPicked = 1;
|
|
|
|
//PlayerPrefs.SetInt(name, isPicked);
|
|
|
|
//gameObject.SetActive(false);
|
2022-06-17 22:22:19 +02:00
|
|
|
|
2022-06-19 14:38:22 +02:00
|
|
|
SceneEquippableItemManager.Instance.RemoveDynamicItem(item.name); // remove
|
|
|
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
Debug.LogError("Can't pick item - Your inventory is full");
|
|
|
|
}
|
2022-06-15 19:54:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-27 21:28:55 +01:00
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
2022-04-19 16:18:30 +02:00
|
|
|
{
|
|
|
|
if (collision.tag == "Player")
|
|
|
|
{
|
2022-06-15 19:54:44 +02:00
|
|
|
triggered = true;
|
2022-04-19 16:18:30 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-15 19:54:44 +02:00
|
|
|
|
|
|
|
private void OnTriggerExit2D(Collider2D collision)
|
|
|
|
{
|
2023-01-06 03:44:07 +01:00
|
|
|
if (collision.tag == "Player")
|
|
|
|
{
|
|
|
|
triggered = false;
|
|
|
|
}
|
2022-06-15 19:54:44 +02:00
|
|
|
}
|
|
|
|
|
2022-06-17 22:22:19 +02:00
|
|
|
// public void SaveCheckpoint()
|
|
|
|
// {
|
|
|
|
// PlayerPrefs.SetInt(name2, isPicked);
|
|
|
|
// }
|
2022-06-15 19:54:44 +02:00
|
|
|
|
2022-04-19 16:18:30 +02:00
|
|
|
}
|