ok i have a script that gives me a random card from a list when called. this works just fine… sometimes… because as said i want only one card to come per call to the script but sometimes (and yes only sometimes) it will give me multiple cards. this is the first bug in this code. my 2nd bug is alot easier to locate but again i hve no idea how to fix because it is only sometimes that the bug comes into affect. so when i instantiate the cards i parent them to the deck working just fine… but i want to put them as SetActive(false) but here again its only sometimes it gets set to false. so my problem summarized:
1: SetActive(false) only work sometimes
2:i get multiple cards sometimes
`public class Deck : MonoBehaviour
{
public GameObject Hand;
public GameObject dDeck;
public GameObject gGarrison;
public GameObject[] Cards = new GameObject[3];
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;
deckCards.Add(Cards[0]);
deckCards.Add(Cards[1]);
deckCards.Add(Cards[2]);
foreach (GameObject card in deckCards)
{
card.transform.SetParent(dDeck.transform);
Debug.Log("Parent set");
card.SetActive(false);
if (card.tag == "Garrison")
{
card.transform.SetParent(gGarrison.transform);
card.SetActive(true);
Debug.Log("garrisons placed");
}
}
}
// Update is called once per frame
void Update()
{
}
public void ChooseRandom()
{
if (Hand.GetComponent<Hand>().RecievedCard == false)
{
randomInt = Random.Range(0, deckCards.Count);
if (deckCards[0 + randomInt].tag == "Garrison")
{
deckCards.Remove(deckCards[0 + randomInt]);
ChooseRandom();
}
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();
}
}
}`