Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by Nargrimm · Mar 07, 2012 at 11:49 PM · objectbeginnergame objectruntime-generation

CCG: Creating a card object

Hello,

I'm fairly new to Unity and currently have a few problems figuring out how to efficiently combine scripts with objects contained in my world. Coming from writing in pure C#, I'm used to treating every class as an object yet this approach sometimes seems to not be working properly.

For example, I am in the process of creating a CCG and have a few problems actually creating the cards. So far I created a prefab which is to be used for cards. This prefab consists of two planes representing front and back of the card, a rigidbody, and a box collider so I can have physically somewhat acurate cards. I want to load cards from a preexisting cardlist at the beginning of a game, so I dont have to create every card within the Unity Editor. Therefore the properties of cards need to be able to be modified at runtime.

Were I in pure C#, I would have a class "Card" containing a variable for every property I'll ever need which would simply be filled as I create the cards for a deck.

My question is how do I go about creating a card object within Unity. Do I just create a single prefab for a card, attach a card script containing potential properties to it, and then just instantiate multiple prefabs when I load the deck? Or how do I attach a physical representation, like the prefab, to an object created by a script?

Sorry for the wall of text, I just hope I made my problem clear enough. This is probably a pretty stupid question, help would still be much appreciated.

Thanks in advance

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Berenger · Mar 08, 2012 at 12:15 AM

I'm not totally sure to understand what you mean but, I'd say you need a prefab with a script Card.cs in which you implement the class Card inheriting from MonoBehaviour. Then make it a prefab. Second step is to have a way to setup all the deck. I see three ways :

  • Duplicate the instanciation of that prefab as many time as you need (in the hierarchy, not the asset folder!) and set it up manually.

  • Create a class CardBuilder (or whatever), which doesn't inherit from anything and with all the var of Card, plus a reference to the prefab. Add [System.Serializable] on top of it so you can see it in the inspector later. Once this is done, Create a MonoBehaviour inherited script with an array of CardBuilder, drag it on an object in the scene and set it up. At runtime, go through that array, Instantiate the prefab and copy the values.

  • If there is a way to build them automatically, you don't need the class above. I guess you have to iterate 13 times * 4 etc.

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
avatar image
0

Answer by Nargrimm · Mar 08, 2012 at 08:35 AM

Yes, this is pretty much exacly what I needed. I've now set it up in a a way, that at the start of the game, the prefab is cloned 50 times for each deck in play and then assigned it's values (right now this is done statically). Shouldn't be too much of a problem assigning these values from a seperate cardlist later down the line. Then every instance created this way is added to a list, holding every card currently in the deck. Thus far this seems to work like a charm.

Thanks a lot for your answer.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How would I implement this game mechanic? 0 Answers

Error message, HELP!!! 1 Answer

Destroy only selected object 1 Answer

Is there a way to shake an Object fast? 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