Помогите сделать крафт в Unity
Я пытался сделать крафт но ничего не вышло видь я ещё новичок . Крафт хотел самый простой . Нажымаеш на иконку предмета и если у тебя есть нужные предметы для крафта предмет крафтитса а предметы для крафта изчезают. Помогите пожалуйста !. Код инвентаря : Inventory
using UnityEngine;
public class Inventory : MonoBehaviour
{
public bool[] isFull; // полон ли слот
public GameObject[] slots; // слоты
}
Slot
using UnityEngine;
public class Slot : MonoBehaviour
{
private Inventory inventory;
public int i;
private void Start()
{
inventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
}
private void Update()
{
if (transform.childCount <= 0)
{
inventory.isFull[i] = false;
}
}
public void DropItem()
{
foreach (Transform child in transform)
{
child.GetComponent<Spawn>().SpawnDropItem();
GameObject.Destroy(child.gameObject);
}
}
}
Spawn
using UnityEngine;
public class Spawn : MonoBehaviour
{
public GameObject item; // игровой обэкт которы виброситса на сцену
private Transform player;
private void Start()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
}
public void SpawnDropItem()
{
Vector2 playerPos = new Vector2(player.position.x, player.position.y + 0.3f); // position
Instantiate(item, playerPos, Quaternion.identity); // создание
}
}
Pick Up
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickUp : MonoBehaviour
{
private Inventory inventory;
public GameObject itemButton; // иконка которая будет отображатса в слоте инвентаря
private void Start()
{
inventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
for (int i = 0; i < inventory.slots.Length; i++) // проходимся по всем слотам
{
if (inventory.isFull[i] == false) // если слот пустой
{
inventory.isFull[i] = true;
Instantiate(itemButton, inventory.slots[i].transform, false);
Destroy(gameObject);
break;
}
}
}
}
}