我有一个问题,当我将物品从库存移到装备物品的位置时,角色可以使用物品图标来拉伸它们。我感觉这与管理它们的老虎机脚本有关,因此当我装备该物品时,请将其删除或放下。
这是我认为需要更改的代码:
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;
}
}