Hi, so i made a list with 10 prefabs in, and i want the shop to randomly pick 5 from the list everytime the shop is opened. I am really new to unity and have been following tutorials up to this point. Thanks.
![alt text][1]
[1]: /storage/temp/126770-forum.png
The code is
namespace Assets.Scripts.UserInterface
{
public class StoreUIController : MonoBehaviour
{
public ItemList MerchantInventory;
[SerializeField]
private GameObject ItemTemplate;
[SerializeField]
private GameObject CurrencyTemplate;
private Transform _scrollViewContent;
private PlayerInventoryUIController _playerInventoryUI;
private void Start()
{
_playerInventoryUI = FindObjectOfType();
}
public void PopulateInventory(ItemList inventoryList)
{
ClearInventory();
MerchantInventory = inventoryList;
if (_scrollViewContent == null)
{
_scrollViewContent = transform.Find("Scroll View").Find("Viewport").Find("Content"); ;
}
foreach (var item in inventoryList.ClothingItems)
{
GameObject newItem = Instantiate(ItemTemplate, _scrollViewContent);
newItem.transform.localScale = Vector3.one;
newItem.transform.Find("Image").GetComponentImage may be NSFW.
Clik here to view.
().sprite = item.Sprite;
newItem.transform.Find("Name").GetComponent().text = item.Name;
newItem.transform.Find("Description").GetComponent().text = item.Description;
foreach (var cur in item.PurchasePrice)
{
GameObject newCurrency = Instantiate(CurrencyTemplate, newItem.transform.Find("Currency/List"));
newCurrency.transform.localScale = Vector3.one;
newCurrency.transform.Find("Image").GetComponentImage may be NSFW.
Clik here to view.
().sprite = cur.Currency.Image;
newCurrency.transform.Find("Amount").GetComponent().text = cur.Amount.ToString();
}
newItem.transform.Find("Currency").Find("BuyBtn").GetComponent
Clik here to view.
Clik here to view.