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
-1
Question by Theromanek100 · Jun 23, 2016 at 10:08 AM · c#gamecardcards

How to sort cards in order from smallest to the largest amount of strength?

Hi. I'am making a card game in Unity 5. I have done, a drag and drop system and random starting cards. But these cards are arranged in the order in which they were drawn and I want them to be in order from smallest strenght to the largest one. And here is my question: How to do this? I was trying to do this myself, but I failed. Here is my project. Sorry for scripts written in Polish ;) If someone needs them to be translate I could do that. Here and here, are some examples what I want to do ;)

PS: I'm giving the hole project, because the same scripts might be hard to understand what is going on in them ;) And sorry for my english :D

Comment
Add comment · Show 5
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 Mindmapfreak · Jun 23, 2016 at 06:14 PM 0
Share

I think you have to describe your problem a little better. Few people (me included) will probably download your whole project and look through it. Is the problem the sorting itself? Then you could do something like this (assu$$anonymous$$g the cards are in a list):

 public class Card
 {
     public float Strength;
     public string Name;
     public Card(string name,float strength)
     {
         this.Name = name;
         this.Strength = strength;
     }   
 }
 ----------------------------------------------------------------------------
 using System.Collections.Generic;
 using System.Linq;
 
 List<Card> cards = new List<Card>();
 cards.Add(new Card("IAmStrong",100.0f));
 cards.Add(new Card("IAmWeak",0.1f));
 cards.Add(new Card("IAmInThe$$anonymous$$iddle",10.0f));
 Debug.Log("Before ordering");
 foreach(Card card in cards)
 {
     Debug.Log(card.Name);
 }
 cards = cards.OrderBy(card=>card.Strength).ToList();
 Debug.Log("After ordering");
 foreach (Card card in cards)
 {
     Debug.Log(card.Name);
 }

avatar image Theromanek100 · Jun 24, 2016 at 01:33 PM 0
Share

@ChrisAngel$$anonymous$$indmapfreak I add links to examples of what I want to do :) In Gwent or Duel of Champions cards are automatically sorted. And that's what I want to do in my game :D

avatar image Mindmapfreak Theromanek100 · Jun 24, 2016 at 02:40 PM 0
Share

Ok, but what exactly is your problem? Displaying the cards? Animations? The sorting itself? Does the code above help you? Can you post some code-excerpts?

avatar image Theromanek100 Mindmapfreak · Jun 24, 2016 at 08:13 PM 0
Share

I worked it out with the sorting of the list, but I do not know how to display them on the table in correct order. That's my biggest problem :/

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

183 People are following this question.

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

Related Questions

Card Game Trouble 0 Answers

Issue with loading scenes with buttons 1 Answer

Problem with checking multiple objects are active. 1 Answer

Unity5/C# beginner here! Need some scripting help :) <3 1 Answer

How do i make advanced Chess AI? 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