Hello i have a question regarding Arrays.
Let’s say i have a CSV file called weapons, i changed that CSV file into a TextAsset file and i would like to have an Array which will hold all my weapons from this TextAsset file and then in my function i will iterate through this Array to create a random number of items.
var weapons : TextAsset;
var itemsListArray : Array;
function InitialiseArray() {
itemsListArray = new Array ();
CreateRandomItemsFromArray();
}
private function CreateRandomItemsFromArray() {
var total : int = Mathf.Clamp(Random.value * 10, 4, 10);
for(var _cnt : int = 0; _cnt < total; _cnt++) {
var temp : int = Random.value * 24;
itemsListArray.Add(temp);
//Debug.Log(_cnt + " -- " + itemsListArray);
}
}
When i am passing weapons as a parameter in itemsListArray = new Array ();
i am getting this error, but the items are being printed in Console.
InvalidCastException: Cannot cast from source type to destination type.
Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (System.Object value)
Boo.Lang.Runtime.RuntimeServices.UnboxInt32 (System.Object value)
Also inside the window which is being opened to create random set of items. My first GUI Button is empty ad the rest of them are having integer values from CreateRandomItemsFromArray function