#Recipe Scriptusing System.Collections.Ge...
1 messages · Page 1 of 1 (latest)
One message removed from a suspended account.
One message removed from a suspended account.
no
One message removed from a suspended account.
One message removed from a suspended account.
it is supposed to be shown when all ingredients are avaible
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
yes
basically the problem is that even though there are not enough materials to craft,it is still craftable
One message removed from a suspended account.
One message removed from a suspended account.
yes
One message removed from a suspended account.
One message removed from a suspended account.
so where do i call it?
One message removed from a suspended account.
One message removed from a suspended account.
ok
One message removed from a suspended account.
One message removed from a suspended account.
public class Recipe : ScriptableObject
{
public List<ItemData> materials = new List<ItemData>();
public ItemData outputitem;
public bool Craftable(Inventory inventory)
{
List<bool> CanCraft = new List<bool>(materials.Count);
Debug.Log(materials.Count);
for (int i = 0; i < materials.Count; i++)
{
Debug.Log(i);
if (inventory.items[i] == materials[i])
{
CanCraft[i] = true;
Debug.Log(CanCraft[i]);
}
}
return CanCraft.TrueForAll(x => x);
}
}
i updated thes cript with debug logs
One message removed from a suspended account.
One message removed from a suspended account.
i did get an error saying the index is out of range
i added a -1 to the material.count in the forloop
One message removed from a suspended account.
now it works even with only 1 material
btw this is before i simplify it
it no longer works
One message removed from a suspended account.
public abstract class Item : ScriptableObject, IEquatable<Item>
{
public int ID;
public string Name;
[TextArea(1,20)]
public string Description;
public Sprite Icon;
public bool IsStackable;
public bool Equals(Item other)
{
return ID == other.ID;
}
}
[Serializable]
public class ItemData : IEquatable<ItemData>
{
public Item item;//{ get; private set; }
public int amount;//{ get; private set; }
public ItemData(Item item)
{
this.item = item;
AddCount();
}
public void AddCount()
{
amount++;
}
public bool Equals(ItemData other)
{
return this == other;
}
public void RemoveCount()
{
amount--;
}
}
this is the class
inventory.items has a list of itemdata
One message removed from a suspended account.
One message removed from a suspended account.
it works now @cunning ivy
i literaly don't have enough words to thank you
that problem was making me insane for days
One message removed from a suspended account.
@cunning ivy sorry to bother you,but there seems to be 2 new issues
i tried changing the recipe to use 2 swords and now when i craft it,it only consumes 1
i think it is because of the recipe instance script
public class RecipeInstance : MonoBehaviour,IPointerClickHandler
{
public Recipe item;
[SerializeField] Image ItemImage;
public void Init(Recipe recipe)
{
item = recipe;
ItemImage.sprite = recipe.outputitem.item.Icon;
name = recipe.name;
}
public void OnPointerClick(PointerEventData eventData)
{
foreach (ItemData item in item.materials)
{
Inventory.Instance.RemoveItem(item.item);
}
for (int i = 0; i < item.outputitem.amount; i++)
{
Inventory.Instance.AddItem(item.outputitem.item);
}
Destroy(gameObject);
}
}
One message removed from a suspended account.
One message removed from a suspended account.
public void RemoveItem(Item item)
{
if (itemdata.TryGetValue(item, out ItemData tryid))
{
tryid.RemoveCount();
InventoryUpdated?.Invoke(this, tryid);
ItemRemoved?.Invoke(this, tryid);
if (tryid.amount == 0)
{
items.Remove(tryid);
itemdata.Remove(item);
}
}
}
the inventory script doesn't accept itemdata,it only accepts items
One message removed from a suspended account.
like this?
public void OnPointerClick(PointerEventData eventData)
{
for (int i = 0; i < item.materials.Count; i++)
{
Inventory.Instance.RemoveItem(item.materials[i].item);
}
for (int i = 0; i < item.outputitem.amount; i++)
{
Inventory.Instance.AddItem(item.outputitem.item);
}
Destroy(gameObject);
}
One message removed from a suspended account.
item.materials is a list of itemdata
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
ok so for the second issue
basically it is a dupe glitch with the equipment system
public void Equip(Weapon weapon)
{
if (this.weapon != null)
{
UnEquip(this.weapon);
}
this.weapon = weapon;
OnEquipWeapon?.Invoke(this, weapon);
}
public void UnEquip(Weapon weapon)
{
if (this.weapon != null)
{
Weapon unequipingweaponing = this.weapon;
Inventory.Instance.AddItem(unequipingweaponing);
weapon = null;
OnUnequipWeapon?.Invoke(this, weapon);
}
}
}
One message removed from a suspended account.
One message removed from a suspended account.
visual studio