I'm working on a card game consisting of 52 unique cards. Found the article/question at (Making Multiple playered Multiplayer Card Game With Mirror) which closely matches some of what I'm trying to do. When I use the code below, I can load the Lists for the Cards - i.e. Card aceOfClubs = new Card() - and add the individual Card data to the Series lists - i.e. clubsSeries.Add(aceOfClubs) - but when I get to adding the cards to the deck using "deck.AddRange(clubsSeries);" I get the following error: Argument 1: cannot convert from 'System.Collections.Generic.List to System.Collections.Generic.IEnumerable<UnityEngine.GameObject>'
Am I overlooking some obvious mistake on my part? Thanks...still a C# newbie but couldn't find anything in searching here or Google...
Below PlayerManager Class;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
using System.Linq;
using UnityEngine.UI;
public class PlayerManager : NetworkBehaviour
{
public GameObject gameBoard;
public GameObject deckPlace;
public GameObject okeyPlace;
public GameObject playerArea;
public List<GameObject> deck = new List<GameObject>();
public List<Card> hand = new List<Card>();
public List<Sprite> cardImages = new List<Sprite>();
public GameObject cardPrefab;
[Client]
public override void OnStartClient()
{
base.OnStartClient();
playerArea = GameObject.Find("PlayerArea");
gameBoard = GameObject.Find("GameBoard");
deckPlace = GameObject.Find("Deck");
okeyPlace = GameObject.Find("OkeyPlace");
}
[Server]
public override void OnStartServer()
{
//Generating Cards
#region Generating FirstDeckOfCards
List<Card> jokers = new List<Card>();
Card joker = new Card()
{
realValue = 1,
name = "Joker",
suit = Card.Suit.joker,
imgSuit = Card.ImageSuit.jokerImg,
subValue = 0,
backFace = Card.Color.cream,
isJoker = true
};
List<Card> clubsSeries = new List<Card>();
//Clubs Series
Card aceOfClubs = new Card()
{
realValue = 1,
name = "Clubs",
suit = Card.Suit.clubs,
imgSuit = Card.ImageSuit.clubsImg,
subValue = 0,
backFace = Card.Color.cream
};
And So on...
#region Joker Cards Are Added To Joker List
jokers.Add(joker);
#endregion Joker Cards Are Added To Joker List
#region Joker2 Cards Are Added To Joker List
jokers2.Add(joker2);
#endregion Joker2 Cards Are Added To Joker List
//Clubs Cards Are Added To ClubsSeries List
#region Clubs Cards Are Added To ClubsSeries List
clubsSeries.Add(aceOfClubs);
clubsSeries.Add(twoOfClubs);
clubsSeries.Add(threeOfClubs);
clubsSeries.Add(fourOfClubs);
clubsSeries.Add(fiveOfClubs);
clubsSeries.Add(sixOfClubs);
clubsSeries.Add(sevenOfClubs);
clubsSeries.Add(eightOfClubs);
clubsSeries.Add(nineOfClubs);
clubsSeries.Add(tenOfClubs);
clubsSeries.Add(elevenOfClubs);
clubsSeries.Add(twelveOfClubs);
clubsSeries.Add(thirteenOfClubs);
#endregion Clubs Cards Are Added To ClubsSeries List
#region Clubs2 Cards Are Added To ClubsSeries List
clubsSeries2.Add(aceOfClubs2);
clubsSeries2.Add(twoOfClubs2);
clubsSeries2.Add(threeOfClubs2);
clubsSeries2.Add(fourOfClubs2);
clubsSeries2.Add(fiveOfClubs2);
clubsSeries2.Add(sixOfClubs2);
clubsSeries2.Add(sevenOfClubs2);
clubsSeries2.Add(eightOfClubs2);
clubsSeries2.Add(nineOfClubs2);
clubsSeries2.Add(tenOfClubs2);
clubsSeries2.Add(elevenOfClubs2);
clubsSeries2.Add(twelveOfClubs2);
clubsSeries2.Add(thirteenOfClubs2);
#endregion Clubs2 Cards Are Added To ClubsSeries List
//Diamonds Cards Are Added To DiamondsSeries List
#region Diamonds Cards Are Added To DiamondsSeries List
diamondsSeries.Add(aceOfDiamonds);
diamondsSeries.Add(twoOfDiamonds);
diamondsSeries.Add(threeOfDiamonds);
diamondsSeries.Add(fourOfDiamonds);
diamondsSeries.Add(fiveOfDiamonds);
diamondsSeries.Add(sixOfDiamonds);
diamondsSeries.Add(sevenOfDiamonds);
diamondsSeries.Add(eightOfDiamonds);
diamondsSeries.Add(nineOfDiamonds);
diamondsSeries.Add(tenOfDiamonds);
diamondsSeries.Add(elevenOfDiamonds);
diamondsSeries.Add(twelveOfDiamonds);
diamondsSeries.Add(thirteenOfDiamonds);
#endregion Diamonds Cards Are Added To DiamondsSeries List
#region Diamonds2 Cards Are Added To DiamondsSeries List
diamondsSeries2.Add(aceOfDiamonds2);
diamondsSeries2.Add(twoOfDiamonds2);
diamondsSeries2.Add(threeOfDiamonds2);
diamondsSeries2.Add(fourOfDiamonds2);
diamondsSeries2.Add(fiveOfDiamonds2);
diamondsSeries2.Add(sixOfDiamonds2);
diamondsSeries2.Add(sevenOfDiamonds2);
diamondsSeries2.Add(eightOfDiamonds2);
diamondsSeries2.Add(nineOfDiamonds2);
diamondsSeries2.Add(tenOfDiamonds2);
diamondsSeries2.Add(elevenOfDiamonds2);
diamondsSeries2.Add(twelveOfDiamonds2);
diamondsSeries2.Add(thirteenOfDiamonds2);
#endregion Diamonds2 Cards Are Added To DiamondsSeries List
//Hearts Cards Are Added To HeartsSeries List
#region Hearts Cards Are Added To HeartsSeries List
heartsSeries.Add(aceOfHearts);
heartsSeries.Add(twoOfHearts);
heartsSeries.Add(threeOfHearts);
heartsSeries.Add(fourOfHearts);
heartsSeries.Add(fiveOfHearts);
heartsSeries.Add(sixOfHearts);
heartsSeries.Add(sevenOfHearts);
heartsSeries.Add(eightOfHearts);
heartsSeries.Add(nineOfHearts);
heartsSeries.Add(tenOfHearts);
heartsSeries.Add(elevenOfHearts);
heartsSeries.Add(twelveOfHearts);
heartsSeries.Add(thirteenOfHearts);
#endregion Hearts Cards Are Added To HeartsSeries List
#region Hearts2 Cards Are Added To HeartsSeries List
heartsSeries2.Add(aceOfHearts2);
heartsSeries2.Add(twoOfHearts2);
heartsSeries2.Add(threeOfHearts2);
heartsSeries2.Add(fourOfHearts2);
heartsSeries2.Add(fiveOfHearts2);
heartsSeries2.Add(sixOfHearts2);
heartsSeries2.Add(sevenOfHearts2);
heartsSeries2.Add(eightOfHearts2);
heartsSeries2.Add(nineOfHearts2);
heartsSeries2.Add(tenOfHearts2);
heartsSeries2.Add(elevenOfHearts2);
heartsSeries2.Add(twelveOfHearts2);
heartsSeries2.Add(thirteenOfHearts2);
#endregion Hearts2 Cards Are Added To HeartsSeries List
//Spades Cards Are Added To SpadesSeries List
#region Spades Cards Are Added To SpadesSeries List
spadesSeries.Add(aceOfSpades);
spadesSeries.Add(twoOfSpades);
spadesSeries.Add(threeOfSpades);
spadesSeries.Add(fourOfSpades);
spadesSeries.Add(fiveOfSpades);
spadesSeries.Add(sixOfSpades);
spadesSeries.Add(sevenOfSpades);
spadesSeries.Add(eightOfSpades);
spadesSeries.Add(nineOfSpades);
spadesSeries.Add(tenOfSpades);
spadesSeries.Add(elevenOfSpades);
spadesSeries.Add(twelveOfSpades);
spadesSeries.Add(thirteenOfSpades);
#endregion Spades Cards Are Added To SpadesSeries List
#region Spades2 Cards Are Added To SpadesSeries List
spadesSeries2.Add(aceOfSpades2);
spadesSeries2.Add(twoOfSpades2);
spadesSeries2.Add(threeOfSpades2);
spadesSeries2.Add(fourOfSpades2);
spadesSeries2.Add(fiveOfSpades2);
spadesSeries2.Add(sixOfSpades2);
spadesSeries2.Add(sevenOfSpades2);
spadesSeries2.Add(eightOfSpades2);
spadesSeries2.Add(nineOfSpades2);
spadesSeries2.Add(tenOfSpades2);
spadesSeries2.Add(elevenOfSpades2);
spadesSeries2.Add(twelveOfSpades2);
spadesSeries2.Add(thirteenOfSpades2);
#endregion Spades2 Cards Are Added To SpadesSeries List
#region Cards Are Added To Deck
deck.AddRange(jokers); //Jokers List Is Added To Deck;
deck.AddRange(clubsSeries); //Clubs Series List Is Added To Deck;
deck.AddRange(diamondsSeries); //Diamonds Series List Is Added To Deck;
deck.AddRange(heartsSeries); //Hearts Series List Is Added To Deck;
deck.AddRange(spadesSeries); //Spades Series List Is Added To Deck;
#endregion Cards Are Added To Deck
}
}
[System.Serializable]
public class Card
{
public int realValue;
public enum Suit { joker, clubs, diamonds, hearts, spades, okeySuit }
public Suit suit;
public enum ImageSuit { jokerImg, clubsImg, diamondsImg, heartsImg, spadesImg }
public ImageSuit imgSuit;
public int subValue;
public enum Color { cream, blue }
public Color backFace;
}
CodePudding user response:
In your deck.AddRange(clubsSeries)
deck
is a List<GameObject>
and clubSeries
is a List<Card>
. So you are trying to add Card
objects to the collection that is working with the GameObject
.
Is there any reason why your hand
is a List<Card>
, but the deck is a List<GameObject>
?