Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by redcap · Dec 10, 2010 at 03:24 PM · playcardplaceshuffle

Cards: Stacking, drawing, hand, and shuffling

I am trying to make a code to simulate simple card mechanics. Moving and drawing cards won't be very hard, but I am struggling with how to make the different cards work as a deck. For example I can make cards out of two sided planes, and move and flip these cards; but I can't get it so that I can shuffle a deck, or place cards back in a deck.

So my questions are, how do I make a group of cards act as a deck to call a shuffle function on?

How do I remove cards from the deck so when I call the shuffle function, it won't shuffle cards that I have played on the table?

How can I add cards to a deck so the shuffle function will work on the deck, even though I added new cards to the original deck?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Justin Warner · Dec 10, 2010 at 03:33 PM

First off, to animate the cards, and actually make them, I'd suggest actually modeling and animating in 3D software, if you want to use Unity, go right ahead however...

Then, make an array the size of the deck (56?), and have it randomly give it a number, have each number 1-56 (0-55 in code) recieve a random number, then have a switch statement for each number to have a texture, a type, and a number, so that for example (psuedo code):

if card is 1, make ace hearts, if card is 2, make 2 of hearts, etc. Apply the texture, and the definition...

Then, when a card is taken out of the deck, have it subtract that from the array (sense arrays are non-mutatable... I guess you can use an ArrayList, unless those aren't used in Unity?)... Use that, can do the same thing, and then you can add and subtract cards with ease... Just have a functions for every little thing, then add them in the main code, and have it do its work...

Hope that steered you in a good direction...

For info on ArrayList's in Unity, check here: http://forum.unity3d.com/threads/24473-Problem-with-ArrayList-with-Prefab-Scripts.-(c-)

And also look around some on here and the forums more... Their are a couple things.

Good luck!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Random Tag Call Script [C#] 3 Answers

Shuffle a deck for a card game 1 Answer

How do I shuffle a list and reset it back to the previous ordering later? 1 Answer

Variables in editor script reset when playing 1 Answer

What does this statement construction mean?: if (null != anim) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges