hi. so this here i also talked about in my last question but now that i have really looked into my code i found where the bug is. or rather i found the bug carrier.
so my trouble is when i make a random call into the list and i end up with the last item in the list it throws an arguement out of range error and then give me the last item AND another item
here is the code
public class Deck : MonoBehaviour
{
public GameObject Hand;
public GameObject dDeck;
public GameObject gGarrison;
public GameObject[] Cards = new GameObject[5];
public List<GameObject> deckCards = new List<GameObject>();
int randomInt;
// Use this for initialization
void Start()
{
Cards[0] = Instantiate(Cards[0], transform.position, transform.rotation) as GameObject;
Cards[1] = Instantiate(Cards[1], transform.position, transform.rotation) as GameObject;
Cards[2] = Instantiate(Cards[2], transform.position, transform.rotation) as GameObject;
Cards[3] = Instantiate(Cards[3], transform.position, transform.rotation) as GameObject;
Cards[4] = Instantiate(Cards[4], transform.position, transform.rotation) as GameObject;
foreach (GameObject card in Cards)
{
card.SetActive(false);
card.transform.SetParent(dDeck.transform);
Debug.Log("Parent set");
if(card.tag != "Garrison")
{
deckCards.Add(card);
}
if (card.tag == "Garrison")
{
card.transform.SetParent(gGarrison.transform);
card.SetActive(true);
Debug.Log("garrisons placed");
}
}
}
// Update is called once per frame
void Update()
{
foreach (GameObject item in deckCards)
{
item.SetActive(false);
}
}
public void ChooseRandom()
{
if (Hand.GetComponent<Hand>().RecievedCard == false)
{
randomInt = Random.Range(0, deckCards.Count);
Hand.GetComponent<Hand>().cardsInHand.Add(deckCards[0 + randomInt]);
deckCards[0 + randomInt].transform.SetParent(Hand.transform);
deckCards.Remove(deckCards[0 + randomInt]);
deckCards[0 + randomInt].SetActive(true);
Hand.GetComponent<Hand>().HaveRecieved();
}
}
}
`