# Flipping Procedurally Generated Cards Individually... How?

I am creating a simple card game based off of “War!” where the player needs to beat the opponent (the computer, for now). The way the game works is simple.

-5 Cards dealt (1 for computer, 4 for Player)

-Computers card is Face Up, Player cards are face down. Once the player chooses their card, all cards are flipped.

The issue I have is that I used a plugin that creates a deck of cards procedurally (for an old iPad Blackjack project), and they automatically flip all cards face up. I dug around through the code and got it to deal all cards face down… but I still need to have the Computer’s card flipped and ultimately all of the player cards when the selection of what card to play has been made.

I started using iTween to call the animation of rotation after the cards are generated but I keep getting iTween errors being thrown around.

Attached you will find the Update (in the plugin) that does the dealing…

``````void Update ()
{
TryBuild();

if (m_flying)
{
float t = Time.time - m_flyTime;
Vector3 pos = transform.position;
Quaternion rot = transform.rotation;
if (t < m_flyDuration)
{
float tt = t/m_flyDuration;
pos = Vector3.Lerp(m_flySource,m_flyTarget,tt);
// parabolic arc to lift card of deck
pos.z += -2*Mathf.Sin(tt*3.14f);
//delay card flip until 25% of flight
/*float rt = Mathf.Clamp01(tt-0.25f)/0.75f;
tt = 1-rt*rt;*/
rot = Quaternion.Euler(0,180,0);
}
else
{
pos = m_flyTarget;
rot = Quaternion.Euler(0,180,0);
m_flying = false;
}
this.transform.position = pos;
this.transform.rotation = rot;
}
}
``````

Anyone have any ideas how I can make this work?

You can simplify this whole thing by using a basic animation that programmatically gets attached to each object. Then you can define the way the card moves in flipping, and then just trigger the animation from whatever command initiates the flipping.

As someone who generally overthinks coding and movement, I can tell you, sometimes the animation system is just easier
c:

I’m not sure how your card data is held, but…
don’t you have an array for player cards, and one variable for CPU cards?
why not just loop through player array when you need them to flip?

your card class could contain bool value like bool isFlipped,
then you can flip whatever cards that has a false value.

hope this helps?