- Home /
Is it possible to remove elements from a Texture2D array?
Hello! I am working on a simple card game to practice my unity skills. I have an array that holds 52 images, representing the deck.
Upon the start of the game, I pull four random cards and attach them to a GUITexture on my game screen. No problems there.
However, I would like to remove these 'used' cards from my array but after much googling, I cannot find a good answer. Any opinions or ideas?
Here is the applicable code:
 #pragma strict
 
 //Card Array
 
 var cards : Texture2D[];
 
 var PlayerCards : Texture2D[];
 
 var targetGUI1 : GUITexture;
 var targetGUI2 : GUITexture;
 var targetGUI3 : GUITexture;
 var targetGUI4 : GUITexture;
 
 function Start () 
 {    
     for(var i = 0; i < 4; i++)
     {
         var myElement = cards[Random.Range(0, cards.Length)];
         
         PlayerCards[i] = myElement;
     }
     
     targetGUI1.texture = PlayerCards[0];
     targetGUI2.texture = PlayerCards[1];
     targetGUI3.texture = PlayerCards[2];
     targetGUI4.texture = PlayerCards[3];
 }
Again, no problems filling each texture with a random card. I would like to know if it's possible to remove the chosen cards from this Texture2D array.
Answer by Eric5h5 · Mar 26, 2013 at 04:49 AM
Built-in arrays are a fixed size and have no facility for removing elements. Use a generic List instead. (Do not use the Array class, or ArrayList.) http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use?#Generic_List
Your answer
 
 
             Follow this Question
Related Questions
New GameObject with GUITexture is a Horribly Incorrect Size 1 Answer
Health Script not working 1 Answer
texture2D opacity?(javascript) 0 Answers
Sort() javascript arrays 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                