- Home /
Question by
Skatola · Mar 24, 2014 at 05:34 AM ·
listrandomgeneric.list
reset a generic list elements
Hi, sorry for my english and tnx in advice :) i have a list of items, this is the script:
static var mazzoHM : boolean = false;
static var mazzoHF : boolean = false;
public var GOHlist = new System.Collections.Generic.List.<GameObject>();
function OnMouseDown(){
var PH = GOHlist.Item[Random.Range(0,GOHlist.Count)];
if (mazzoHM == true){
audio.Play();
Instantiate (PH);
GOHlist.Remove(PH);
}
this works great but i have one problem, when the list elements reach 0 (all the elements are randomly picked) i want to reset the list and restore all the items removed, just like reshuffle a deck when it ends, how can i do that? sry again for my english i hope u understood my trouble :)
Comment
Best Answer
Answer by whydoidoit · Mar 24, 2014 at 05:41 AM
Something like this:
public var copyOfList : new System.Collections.Generic.List.<GameObject>();
function Start() {
copyOfList.AddRange(GOHList);
}
function ResetList() {
GOHList.Clear();
GOHList.AddRange(copyOfList);
}
Glad to help, please tick my answer to mark it closed and get us both some karma :)
Your answer

Follow this Question
Related Questions
A node in a childnode? 1 Answer
Making a camera list 1 Answer
How to assign a variable individually for each element of an object list 1 Answer
Count selected item in List 1 Answer