I’m making a simple RPG for practice purposes and I want to count the number of dungeons the player beat. Based off of that number, I want to let the player buy different items.
Each item has a class where it has a public getter and setter saying how many dungeons must be beaten to display the item. How can I use a script to control all of the items that can be purchased with the int dungeonsBeaten?
Have a script that checks the dungeonBeaten int compared to the Items requiredDungeons value whenever the shop is opened and make a list of available items for purchase.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;//required to use Lists
public class DungeonCountController : MonoBehaviour {
public Item[] allItems; //Assign the items in your inspector
public List<Item> availableItems;
// Use this for initialization
void Start () {
availableItems = new List<Item> ();
}
public void DungeonCheck(){// call this when the shop is opened
availableItems.Clear();
foreach (Item item in allItems) {
if (dungeonsBeaten >= item.requiredDungeons ) {
availableItems.Add (item);
}
}
}
}
You can then use the contents of the availableItems list to display all the items the player can buy with their current number of dungeonsBeaten.