I’m trying to make a deck of cards and the player should be able to draw a random card from the deck (clone) and then move it to hand ,the problem is that it’s look like the movement happen in just one frame… i’m new to unity and c# .
void Update()
{
if (isdraw)
{
Debug.Log("pressssd");
StartCoroutine("MoveDealtCard");
}
isdraw = false ;
}
GameObject DealCard()
{
if (cards.Count == 0)
{
showReset = true;
return null;
//Alternatively to auto reset the deck:
//ResetDeck();
}
int card = Random.Range(0, cards.Count - 1); //pick a random card index
GameObject go = GameObject.Instantiate(cards[card]) as GameObject; //Clones the object original
cards.RemoveAt(card);
if (cards.Count == 0)
{
showReset = true;
}
return go; //returns the clone
}
IEnumerator MoveDealtCard()
{
GameObject newCard = DealCard();
// check card is null or not
if (newCard == null)
{
Debug.Log("Out of Cards");
showReset = true;
yield return null;
}
//newCard.transform.position = Vector3.zero;
// newCard.transform.position = new Vector3((float)cardsDealt / 4, (float)cardsDealt / -4, (float)cardsDealt / -4); // place card 1/4 up on all axis from last
float step = speed * Time.deltaTime;
newCard.transform.position = Vector3.MoveTowards(transform.position, target.position, step);
hand.Add(newCard); // add card to hand
cardsDealt++;
yield return null;
}