Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by MJG1123 · Oct 28, 2015 at 12:54 PM · spriteimagecardmanagement

How to better manage switching out card sprites when loading a card from a deck

In my game the player is constantly switching out cards in and out of play and I have four cards that load different stats that can be in play at a given time instead of making like 50+ prefabs is their a way to better manager switch out the sprites.

For the other variables I just have a else if statement system and that works fine but I can't load sprites the same way, the only way unity will load them is if I have a script that just handles images like this

Update if (card a = "this card name") this card.sprite = Resources.loadetc

I cant find any info on a solution because no one seems to be making a card game or etc like mine

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
0

Answer by Dibbie · Jun 14, 2016 at 07:55 AM

Well this isnt specific to just card games... Iv recently created a 2D arena/fighting game using the same idea, one prefab as a generic character, scripts to handle the stats, and a global script that handles spawning that 1 prefab, and altering the stats and sprite of that prefab, based on specific conditions in my game. You could mimic the same idea.

Create your one prefab card, kind of as a "template" with all the scripts on it, then by a seperate script - probably the one that handles allowing the player to switch between cards or some type of "global" script, create conditions that will have your script know which image to switch the Instantiated card to. Depending on how you handle your "conditions" your method may be different.

For example, you can do it by "card name", or "card id", and switch the sprite from an array, with the same index as the "card id".

Essentially, the logic you are using now (if you prefer to load everything from Resources instead of setting it in the inspector), is probably the best way to do it, you are checking if its one specific condition that will always return one "card" in your case, and setting the sprite to a specific sprite based on that.

To avoid your "like 50+" if-statements, you would reference your prefab to the script that should be updating its sprite, and in your prefab whenever this card changes, and the name of the card is updated, make sure that name is public - be it the game obects name, or a public string variable that represents the name in a script attached to the card, and instead of: if (cardA = "this card name"), it would then be: if(cardInEffect = cardA.name).

So there are a few ways you can approach it.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How can i save the image of the object OnApplicationQuit 0 Answers

How to set prefab images from script? 2 Answers

How I can change the sprite of the image because the code doesn't work? 1 Answer

Changing UI Image's sprite, preserve aspect ratio is checked but not working? 0 Answers

Inconsistent visibility of small sprites 0 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