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 Itchigon · Feb 11, 2013 at 04:55 PM · 2dprefabobjectcard

Making a card

I am making a card-based game similar to Triple Triad. The game is played in top-down 2D over a 3x3 grid where players place their cards onto one of the open grid positions. Therefore I need to make a card which is 2D, holding a picture on its face and a different picture on its back so that when animating a card to flip it would look like an actual card.

The game will have about 30 cards with different pictures and other things (each card has 4 values in the north, east, south and west positions on the face of the card).

How would I go about making these cards to use in my game? I have read something about prefabs but just asking in case there is another option or perhaps a better example for my case?

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
Best Answer

Answer by robertbu · Feb 11, 2013 at 05:24 PM

Create a single card prefab. The prefab would be composed of a background with a blank front, a plane to display the face of the card on and a script. The script would contain some public variables or methods to set the value for the face of the card. In the script there would be an array of textures something like:

public Texture[] artex; // C#

var artex : Texture[]; // Unityscript

All your face textures for all your cards would go into this array. Then at runtime, you would Instantiate() the deck of 30 cards (or only the 9 you need) and assign them values. The card would then set the texture for the face of the card according to the value you assigned to the card. Something like:

renderer.material.mainTexture = artex[i];

If your target platform is mobile, I'd test performance of this (or any) solution early. If it is too slow, you can use a texture atlas instead of individual textures for the face of the cards. Add-on packages like EZGUI and I assume NGUI make this fairly easy.

Comment
Add comment · Show 9 · 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
avatar image Itchigon · Feb 11, 2013 at 07:26 PM 0
Share

When you say 'the prefab would be composed of a background with a blank front', how do I go about making that in Unity? Am I right in thinking you mean create a Cube and then put a plane in front of the cube?

avatar image robertbu · Feb 11, 2013 at 07:46 PM 0
Share

A cube and a plane would work, though unless you UV map it, the edges and the blank face will get a copy of the back. If you don't care about thickness, two planes back to back would work. One would be a child of the other. FYI, the build-in planes are one sided.

avatar image robertbu · Feb 11, 2013 at 08:11 PM 0
Share

And if you use two built-in planes, I'd parent both to an empty game object. Planes are horizontal by default, so later if you want to do some form of script-based animation, you have to deal with the rotation. Parenting to an empty game object so the cards are in their play position when the empty game object as rotation of (0,0,0) will simplify things. You might also take a look at the CreatePlane editor script. It will make vertical planes and use less triangles (probably not an issue for your game).

avatar image Itchigon · Feb 12, 2013 at 08:02 PM 0
Share

I have created a 'Card' prefab which is two planes. I have made a script called 'Card' also which is added to the prefab and contains:

4 int's for the four values (N,E,S,W, e.g. 1, 7, 2, 3). 1 string for name of card and a constructor method public Card to set the values

So, because my cards all have different values on them (e.g. one could have 1, 7, 2, 3 and another could have 5, 9, 1, 1) how would I go about creating the cards, would I just make them one at a time using the constructor? $$anonymous$$g. creating new cards when user clicks New Game:

Card card1 = new Card(name, topValue etc)

If this is good enough how would I then set the face of each card, could I send a texture parameter to the constructor and then do something like call the following method inside it:

void ApplyTexture(Texture t) { renderer.material.mainTexture = t;
}

Would that set the individual card to the texture specified?

avatar image robertbu · Feb 13, 2013 at 06:20 AM 0
Share

First off, if the script is attached to a game object, it should not have a constructor. Initialization should be done in Start().

How you create cards will partly depend on the game. I don't understand the values assigned to the cards. How many unique cards can exist in a game? In a traditional deck there are four suits, and 13 value cards. But if you use for integers (even assu$$anonymous$$g you confine them to (0 - 9), you will have 10 10 10 * 10 possible cards, but you indicate in your original question that you will only have 30 total cards.

And how many cards can show at one time? Will there only be 9 cards showing?

And is this game for mobile, web, or desktop?

Show more comments

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple timers on server as objects or prefabs? 0 Answers

Instantied 2D Prefab Is Invisible 1 Answer

How to instantiate a gameobject by aligning it to another one 2 Answers

Infinity runner - best way to spawn board in runtime. 0 Answers

Avoid getting same object as previous one with Random.Range? 2 Answers


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