Я следовал учебнику, в котором кто-то написал "publi c Inventory Container;" с помощью которого он мог получить доступ к данным из сценария инвентаризации. Почему это возможно? Я думал, что вы можете получить доступ к неинстанцированному скрипту, только если он установлен c. Спасибо за помощь
Первый сценарий:
[CreateAssetMenu(fileName = "New Inventory", menuName = "Inventory System/Inventory")]
public class InventoryObject : ScriptableObject
{
public Inventory Container;
public void AddItem(Item _item, int _amount)
{
if (_item.buffs.Length > 0)
{
Container.Items.Add(new InventorySlot(_item.Id, _item, _amount));
return;
}
for (int i = 0; i < Container.Items.Count; i++) //Checks if already has the item.
{
if(Container.Items[i].item.Id == _item.Id)
{
Container.Items[i].AddAmount(_amount); /*If the item already exits, it just increases the number of it.
AddAmount works, because the Container consists of InventorySlot.*/
return;
}
}
Container.Items.Add(new InventorySlot(_item.Id, _item, _amount)); /*If Item doesn't exist, it adds it using the InventorySlot Constructor.*/
}
}
Доступ к сценарию:
[System.Serializable]
public class Inventory
{
public List<InventorySlot> Items = new List<InventorySlot>();
}