Random Hit Card

Hi!

I’m working on a card game.
I want when the dealer has between 15-17 HandValue, to choose whether to draw a card or not, to be totally randam.

The script is this;
void HitDealer()
{
int card = deck.Pop();

if (dealersFirstCard < 0)
{
dealersFirstCard = card;
}

dealer.Push(card);
if (dealer.CardCount >= 2)
{
CardStackView view = dealer.GetComponent();
view.Toggle(card, true);
}
}

IEnumerator DealersTurn()
{
hitButton.interactable = false;
stickButton.interactable = false;

CardStackView view = dealer.GetComponent();
view.Toggle(dealersFirstCard, true);
view.ShowCards();
yield return new WaitForSeconds(1f);

while (dealer.HandValue() < 17)
{

HitDealer();
yield return new WaitForSeconds(1f);
} }

Random.value will return a random float value between 0 and 1, so you can write something like:

float myRand= Random.value;

if (myRand > 0.5f)
{
   //do this
}
else
{
   //do that
}
1 Like

Thx
I solved