Scriptum/Assets/Scripts/Item/PickableController.cs
2022-11-24 03:03:30 +01:00

79 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class PickableController : MonoBehaviour
{
public EquippableItem item;
public string name;
public string name2;
public bool triggered;
public int isPicked;
public int HandleIndexInScelenObjectList;
public void Start()
{
// if object after beeing created by Instaniate() gets "Clone)" postfix, EquippableItem.name gets this
item.Name = gameObject.name;
// if (PlayerPrefs.GetInt("continued") == 1)
// {
// isPicked = PlayerPrefs.GetInt(name2);
// }
// else
// {
// isPicked = PlayerPrefs.GetInt(name);
// }
if(isPicked == 1)
{
//gameObject.SetActive(false);
Destroy(gameObject);
}
}
void Update()
{
if(triggered)
{
if (Input.GetKeyDown(KeyCode.E))
{
if(!InventoryUIManager.Instance.IsFull())
{
InventoryUIManager.Instance.Add(this.item);
isPicked = 1;
//PlayerPrefs.SetInt(name, isPicked);
//gameObject.SetActive(false);
SceneEquippableItemManager.Instance.RemoveDynamicItem(item.name); // remove
Destroy(gameObject);
}else
{
Debug.LogError("Can't pick item - Your inventory is full");
}
}
}
}
private void OnTrigerEnter2D(Collider2D collision)
{
if (collision.tag == "Player")
{
triggered = true;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
triggered = false;
}
// public void SaveCheckpoint()
// {
// PlayerPrefs.SetInt(name2, isPicked);
// }
}