У меня проблема в том, что когда я перемещаю что-то из своего инвентаря туда, где я экипирую предметы, чтобы мой персонаж мог использовать их, значок предмета растягивается.У меня такое ощущение, что это как-то связано со сценарием слота, в котором я ими управляю, поэтому, когда я надеваю предмет, удаляю его или бросаю предмет.
Вот эталонное фото, чтобы вы могли увидеть, что не так:
Вот код, который, я думаю, мне нужно изменить:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Slot : MonoBehaviour
{
public Transform player;
EquipmentManager equipmentManagerScript;
public GameObject item;
public int ID;
public string type;
public string description;
public bool empty;
public Transform slotIconGO;
public Sprite icon;
public GameObject dropBtn;
public Sprite itemBG;
private void Start()
{
equipmentManagerScript = GetComponent<EquipmentManager>();
slotIconGO = transform.GetChild(0);
}
private void Update()
{
#region ToggleDropBTN
if (transform.childCount >= 3)
{
dropBtn.SetActive(true);
}
else
{
dropBtn.SetActive(false);
}
#endregion
}
public void UpdateSlot()
{
slotIconGO.GetComponent<Image>().sprite = icon;
item.SetActive(false);
}
public void UseItem()
{
Inventory inventoryScript = player.GetComponent<Inventory>();
if (transform.GetComponent<Slot>().type == "Weapon")
{
print("Equiped: " + item.name);
for (int i = 0; i < inventoryScript.equipSlots.Length; i++)
{
if (inventoryScript.equipSlots[i].tag == "WeaponSlot" && inventoryScript.equipSlots[i].GetComponent<Slot>().empty == true)
{
if (inventoryScript.equipSlots[i].transform.childCount <= 2)
{
var InstalizeSlot = inventoryScript.equipSlots[i].GetComponent<Slot>();
item.transform.parent = inventoryScript.equipSlots[i].transform;
InstalizeSlot.item = item;
InstalizeSlot.ID = ID;
InstalizeSlot.type = type;
InstalizeSlot.description = description;
InstalizeSlot.empty = false;
InstalizeSlot.icon = icon;
InstalizeSlot.UpdateSlot();
//SET EVERYTHING TO NULL
slotIconGO.GetComponent<Image>().sprite = itemBG;
item = null;
ID = 0;
type = null;
description = null;
empty = true;
icon = null;
}
}
}
}
else if (transform.GetComponent<Slot>().type == "Head")
{
print("Equiped: " + item.name);
for (int i = 0; i < inventoryScript.equipSlots.Length; i++)
{
if (inventoryScript.equipSlots[i].tag == "HeadSlot" && inventoryScript.equipSlots[i].GetComponent<Slot>().empty == true)
{
if (inventoryScript.equipSlots[i].transform.childCount <= 2)
{
var InstalizeSlot = inventoryScript.equipSlots[i].GetComponent<Slot>();
item.transform.parent = inventoryScript.equipSlots[i].transform;
InstalizeSlot.item = item;
InstalizeSlot.ID = ID;
InstalizeSlot.type = type;
InstalizeSlot.description = description;
InstalizeSlot.empty = false;
InstalizeSlot.icon = icon;
InstalizeSlot.UpdateSlot();
//SET EVERYTHING TO NULL
item = null;
ID = 0;
type = null;
description = null;
empty = true;
slotIconGO.GetComponent<Image>().sprite = itemBG;
icon = null;
}
}
}
}
else if (transform.GetComponent<Slot>().type == "Chest")
{
print("Equiped: " + item.name);
for (int i = 0; i < inventoryScript.equipSlots.Length; i++)
{
if (inventoryScript.equipSlots[i].tag == "ChestSlot" && inventoryScript.equipSlots[i].GetComponent<Slot>().empty == true)
{
if (inventoryScript.equipSlots[i].transform.childCount <= 2)
{
var InstalizeSlot = inventoryScript.equipSlots[i].GetComponent<Slot>();
item.transform.parent = inventoryScript.equipSlots[i].transform;
InstalizeSlot.item = item;
InstalizeSlot.ID = ID;
InstalizeSlot.type = type;
InstalizeSlot.description = description;
InstalizeSlot.empty = false;
InstalizeSlot.icon = icon;
InstalizeSlot.UpdateSlot();
//SET EVERYTHING TO NULL
item = null;
ID = 0;
type = null;
description = null;
empty = true;
slotIconGO.GetComponent<Image>().sprite = itemBG;
icon = null;
}
}
}
}
}
public void DequipItem()
{
Inventory inventoryScript = player.GetComponent<Inventory>();
for(int i = 0; i < inventoryScript.slot.Length; i++)
{
if(inventoryScript.slot[i].transform.childCount <= 2)
{
var InstalizeSlot = inventoryScript.slot[i].GetComponent<Slot>();
item.transform.parent = inventoryScript.slot[i].transform;
InstalizeSlot.item = item;
InstalizeSlot.ID = ID;
InstalizeSlot.type = type;
InstalizeSlot.description = description;
InstalizeSlot.empty = false;
InstalizeSlot.icon = icon;
InstalizeSlot.UpdateSlot();
//SET EVERYTHING TO NULL
item = null;
ID = 0;
type = null;
description = null;
empty = true;
slotIconGO.GetComponent<Image>().sprite = itemBG;
icon = null;
}
}
}
public void DropItem()
{
transform.GetChild(2).gameObject.SetActive(true);
transform.GetChild(2).transform.position = player.transform.position + new Vector3(0, 2, 0);
transform.GetChild(2).transform.parent = null;
//SET EVERYTHING TO NULL
item = null;
ID = 0;
type = null;
description = null;
empty = true;
slotIconGO.GetComponent<Image>().sprite = itemBG;
icon = null;
}
}