using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Inventory : MonoBehaviour
{
[SerializeField] List<Item> items;
[SerializeField] Transform itemsParent;
[SerializeField] ItemSlot[] itemSlots;
public Item item;
public float currentweight = 0;
public float totalweight = 100;
private void Start()
{
}
private void OnValidate()
{
if (itemsParent != null)
itemSlots = itemsParent.GetComponentsInChildren<ItemSlot>();
RefreshUI();
}
private void RefreshUI()
{
int i = 0;
for(; i < items.Count && i < itemSlots.Length; i++)
{
itemSlots.item = items;
currentweight += item.weight;
}
for(; i < itemSlots.Length; i++)
{
itemSlots.item = null;
}
}
public bool AddItem(Item item)
{
if(IsFull())
return false;
currentweight += item.weight;
items.Add(item);
RefreshUI();
return true;
}
public bool RemoveItem(Item item)
{
if (items.Remove(item))
{
currentweight -= item.weight;
RefreshUI();
return true;
}
return false;
}
public bool IsFull()
{
return items.Count >= itemSlots.Length;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum ItemQuality
{
Trash,
UnCommon,
Common,
Rare,
Epic,
OneOfAkind,
}
public enum ItemType
{
Consumable,
Resource,
Tool,
Armor,
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "Item")]
public class Item : ScriptableObject
{
[Header("ItemStats")]
//name
public string itemName;
//icon
public Sprite Icon;
//item description
public string itemDescription;
//Id
public int itemID;
//Weight
public float weight;
//stack
public int amount;
//maxstacks
public int maxstacksize;
[Header("ItemAppereance")]
//Item Appreance
public GameObject gameObject;
[Header("Price")]
//price
public float price;
//sale price
public float sellprice;
[Header("Experience")]
//xp
public int expierence;
//maxxp
public int maxexperience;
[Header("Level")]
//curlvl
public int currentlevel;
//maxlvl
public int maxlevel;
//xpneeded
public int xpneededtolevel;
public float Weight
{
get { return weight; }
set { weight = value; }
}
}
Trying to add my items weight to the current weight on the inventory script I wrote. The way itâs currently setup establishes a value and just set every time to that regardless of indivisual variable. I want it to read the items variable than addd the weight of that item. Not just assume every item has a weight of 5. Iâm kind of at a loss on how.