- Home /
Card arrangement
Hi guys, i have a problem. I have several cards in my hand, when a take one off the others must move one position to the left, anyone know any algorithm for this situation?
Answer by highpockets · Feb 02, 2014 at 07:23 PM
Just get the transform.position.x of the card that you are moving down. Then run a foreach statement to cycle through the array of cards and any card in the array that has a transform.position.x that is higher than the card that you moved has to move one space to the left with an immediate jump by just assigning a new transform.position or a nice even slide by using Lerp or Translate if you don't care about acceleration/deceleration ..
Hope that helps. If you don't understand something, let me know and I can give more details
Hey, thanks for your reply :)
Just a different question, do you have any tips on how to arrange the cards in a circular way? Just like you hold it in real life. thanks in advance :)
I think you should ask a new question with specifics. This would be helpful for someone else looking for the same kind of thing that you are. I would however suggest that you simply make an empty game object if there is no hand object and arrange the cards as child objects of the empty game object/hand object in the unity editor and just make a prefab of that. Then, if any cards replace the existing cards, you already have your positions and rotations of the existing cards, so just destroy or move the old one while saving the transform position and rotation and apply that info to the replacement cards transform. Hope that helps
Your answer
Follow this Question
Related Questions
Array Ordering 3 Answers
Trying to sort an array. What's wrong here? 1 Answer
Sorting an array of vectors in javascript 1 Answer
On which place is my value in array? 1 Answer
How unity arrange an Object's child ? 5 Answers