When we use Resources.LoadAll i guess we load all the inventoryitems into a list? in this case we use var, why dont we use InventoryItem itemList in this case? and why do we have a (" ") at the end?
ps. the square brackets became a square.

var is just shorthand. It’s an ‘implicit’ type declaration. The compiler will infer that the return type for Resources.LoadAll<InventoryItem>() is InventoryItem[] and the type will then be InventoryItem[]. So, essntially, we are using InventoryItem[] itemList - which is the ‘explicit’ type declaration.

The Resources.LoadAll function requires a path to be given to it. We supply an empty string as the path. This means it will look through all the resources. The empty string is the root. We could, for instance, have all the items in a resource folder like

  +- Resources
        += InventoryItems

in which case we could use Resources.LoadAll<InventoryItem>("InventoryItems"); to only load items found in the Assets/Resources/InventoryItems folder.


fantastic thnx!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms