Firstly Im very new at this, I’ve messed with scripting in the past on a small scale, So im no pro at c#.
So Anyways,
I have an array that I have stored a Deck of Cards in. When a new card is created it randomly picks a element from the deck of cards and creates the card.
I guess my first question I need to ask, Is when removing an element from an array how does it reorganize the array. Say the array has a length of 10, If I delete depth 5 of the array, does the rest of the array shrink automatically,as In will the element 6 become 5 and so on. If it doesnt how do I reorganize the array so i dont have a empty element.
Second part of my question is after it creates the card I want to delete that particaluar element of the array so that card can not be created again. how do I delete from an array.
Here is creating my card from the array i want to delete the element of the array that i get from the int drawCard :
newCard.gameObject.GetComponent<SpriteRenderer>().sprite = arrayOfPairs[drawCard].cardSprites[0];
Here is my whole code :
using UnityEngine;
using System.Collections;
public class testing : MonoBehaviour {
public GameObject blankCard;
public MyPairs[] arrayOfPairs;
public int cardimage;
int drawCard;
int handSize = 0;
int NewCard = 0;
int deckSize = 9;
// Use this for initialization
void Start () {
while(handSize < 9)
{
drawCards();
handSize++;
}
}
// Update is called once per frame
void Update () {
}
void drawCards(){
GameObject newCard = (GameObject)Instantiate(blankCard);
newCard.name = ("newCard" + NewCard);
NewCard++;
drawCard = Random.Range (0, deckSize);
newCard.gameObject.GetComponent<SpriteRenderer>().sprite = arrayOfPairs[drawCard].cardSprites[0];
}
}