I cant make a system where there are set probabilities of each item and how random.range works. If you have played runescape back in the day you would understand what i mean in more detail…
I’ve never played Runescape, but I wrote this piece of code for you. I’m not really sure if this is what you want.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MediumClueDropTable : MonoBehaviour
{
private void Start()
{
// here are your two arrays
int[] itemId = {0, 1, 2, 3, 4, 5};
string[] itemName = {"a", "b", "c", "d", "e", "f"};
if (itemId.Length != itemName.Length)
{
Debug.Log("arrays are of different length!");
return;
}
// this for loop creates new Item struct, takes one element with the same index from each array and puts them into this struct. Next, the struct "item" is added to the list "items". And now the list is ready to be shuffled.
List <Item> items = new List<Item>();
for (int i = 0; i < itemId.Length; i++)
{
Item item = new Item(itemId_, itemName*);*_
* items.Add(item);*
* }*
* // this is the method where the shuffle is performed. The list is passed by reference, which means that the “items” variable will hold the reference to the randomized list.*
* this.Shuffle(ref items);*
* // this loop will show the items in the console. The reason why it is in the try/catch block is that there can be possibility that the list will be empty.*
* try*
* {*
* foreach(Item item in items)*
* {*
* Debug.Log(item);*
* }*
* }*
* catch {}*
* }*
* // this is the method where shuffle happens.*
* private void Shuffle(ref List items)*
* {*
* try*
* {*
* int count = items.Count;*
* List randomizedItems = new List();*
* for (int i = 0; i < count; i++)*
* {*
* int rand = Random.Range(0, items.Count);*
* randomizedItems.Add(items[rand]);*
* items.RemoveAt(rand);*
* }*
* items = randomizedItems;*
* }*
* catch*
* {*
* Debug.Log(“fill the list with items!”);*
* }*
* }*
}
// this is the struct. It acts as the container for each itemId and itemName and helps to perfom the shuffle.
public struct Item
{
* public int ItemId {get;set;}*
* public string ItemName {get;set;}*
* public Item(int itemId, string itemName)*
* {*
* this.ItemId = itemId;*
* this.ItemName = itemName;*
* }*
* public override string ToString()*
* {*
* return "itemId: " + this.ItemId + ", itemName: " + this.ItemName + "
";*
* }*
}