I’m creating a game where the player can put 4 objects in any combination, even 4 of themselves. What would be the best method of going about this, and letting the game cycle through the list the player created based on a timer.
Example: The player has 4 weapons: Katana, Axe, Spear, Chakram. The player can set the order to Chakram, Chakram, Katana, Spear. The game will give the player the item based on the list they set.
First, you could make a class called ‘weapon’, which stores the type of weapon you have, and its damage etc. It would be nicer to make it a scriptable object too, but for this example, I’m not:
public class Weapon
{
public WeaponType type { get; set; }
}
public enum WeaponType
{
Katana,
Axe,
Spear,
Chakram
}
Then, you could make a list of Weapons, in which the user can pick the weapon type of each item in the list. Is this random? If so you could write:
public class Inventory : MonoBehaviour
{
Weapon[] weapons = new Weapon[4];
private void Start()
{
for (int i = 0; i < weapons.Length; i++)
{
weapons*.type = (WeaponType)Random.Range(0, 3);*
}
}
}
Finally, for the game to cycle through the list based on a timer, I would use an IEnumerator. For example:
public class Inventory : MonoBehaviour
{
Weapon[] weapons = new Weapon[4];
List InventoryWeapons = new List();
private void Start()
{
for (int i = 0; i < weapons.Length; i++)
{
weapons*.type = (WeaponType)Random.Range(0, 3);*
}
StartCoroutine(GiveWeapons(1));
}
IEnumerator GiveWeapons(float delay)
{
for (int i = 0; i < weapons.Length; i++)
{
yield return new WaitForSeconds(delay);
InventoryWeapons.Add(weapons*);*
}
}
}
Is this what you needed? You’ll see the player’s list of weapons slowly fill up in the inspector. @unity_bJkbi0kaeUn_TQ