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
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);
}
@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
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?
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 :/
Your answer
Follow this Question
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