So, I am a complete beginner who wants to make this simple game using 30 cards from normal deck of cards. So can you tell me how to get started with it’s instantiation and it’s shuffle mechanics. I have basic knowledge in scripting but have less clue in its terminology. So even small tips will help. Thank you
That question is pretty vague. There is a post that was recently bumped in this section about shuffling cards that could help you. As for the instantiating - what do you mean/are you looking to know? Edit: btw, this is thread to which I was referring (it's not only about shuffling, but includes it) : https://forum.unity.com/threads/c-poker-hands.493740/ Beyond that, I would suggest that you do some beginner tutorials from Unity ... make a small game following an example, and read some scripting tutorials. Then, "advance" by taking what you've learned and trying to modify and/or expand upon the idea, so you can become comfortable with Unity, scripting, and making a game. Come back to your 30-card game from time to time, as you learn, and work with it Here are some links to what I mentioned, if you're interested: https://unity3d.com/learn/tutorials/s/scripting https://unity3d.com/learn/tutorials/topics/interface-essentials https://unity3d.com/learn/tutorials https://unity3d.com/learn/tutorials/s/roll-ball-tutorial https://unity3d.com/learn/tutorials/s/space-shooter-tutorial
So as I said I’m not very familiar with the terminology. It’s a pretty simple game with simple rules mechanics which I used to play when I was younger. I have figured out all the logic in my head I just can’t totally put it down on code if that makes any sense. So for example from parsing through google , unity forums and c# forums(also the post you mentioned helped a lot too) . I have done a program which makes a list of all the cards and game objects for them but how do I link the GOs to each specific object on the list? (If that makes any sense). But I’m sure I have made lots of progress according to my level today. Thanks for the advice that might help me too Edit: nope I didn’t see that thread before. Will look through it thanks.
Code (CSharp): public struct Card { public enum suit_enum {hearts=0,diamond,club,spade} public enum face_enum {seven=0,eight,nine,ten,j,q,k,a} public suit_enum suit; public face_enum face; }; public class Deck { public List<Card> deck ; public Deck(){ deck = new List<Card> (); } public void Generate(){ Card newCard = new Card (); int RanNum1 = Random.Range (0, 4); int RanNum2 = RanNum1; while(RanNum2 == RanNum1){ RanNum2 = Random.Range (0,4); } for (int i=0; i != 4; i++) { for (int j =0; j!=8; j++) { newCard.suit = (Card.suit_enum)i; newCard.face = (Card.face_enum)j; this.deck.Add (newCard); Debug.Log ("Card '" + newCard.face + "' of '" + newCard.suit + "' added."); GameObject newcardobject = new GameObject("Card_" + newCard.suit + "_" + newCard.face +""); if (j == 0 && (i == RanNum1 || i == RanNum2)) { deck.Remove (newCard); Debug.Log ("Card '" + newCard.face + "' of '" + newCard.suit + "' removed."); GameObject.Destroy(newcardobject); } } } } } so this is the code i have so far. Still have to implement shuffle and draw. But hopefully this clears up my former question.
You could have it so there's a script on each game object. That script could be the card (data), or reference a card object. Then, your list of cards would be scripts on game objects, and therefore you could access '.gameObject' on (any) Card. Hope that helps.