Hi, everyone!
I’m currently making a card game, more specifically a partial clone of Inscryption, and I’m now programming the logic for the deck.
For now, I just have an empty Game Object with a script attached to it with a list.
The list works correctly as I want to fill it manually through the inspector.
I made the cards using Scriptable Objects.
Here’s the thing, I want to shuffle this list without changing the number of times a card is in the list. For example:
A deck with 30 card that contains:
- 10 Wizards
- 10 Warriors
- 10 Assasins
All I have found for now are people randomizing the list, but the problem is that I’m unable to control the how many cards of a specific type are in the deck.
Here’s the code I have right now:
For the Deck:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerDeck : MonoBehaviour
{
public List<PlayableCard> deck = new List<PlayableCard>();
}
For the Scriptable Objects I use for the cards:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
[CreateAssetMenu(fileName = "New Playable Card", menuName = "Playable Card")]
public class PlayableCard : ScriptableObject
{
public new string name;
public int scriptableCardPower;
public int scriptableCardHealth;
public bool scriptableCardIsMox;
public bool scriptableCardEmeraldCost;
public bool scriptableCardRubyCost;
public bool scriptableCardSapphireCost;
public Sprite scriptableCardImage;
}
I've tried the first method but it gives me an error for "rng" (doesn't exist in this context). I think I'm missing something, plus im really new to Unity so I don't understand the code enough to fix the issue or know what is missing.
– ElSuperMagikarp@ElSuperMagikarp You need to define a random generator first. Add this line of code on top of your code: Random rng = new Random();
– NorthStar79