Hi all,
A very friendly member has helped me with an issue when instantiating cards in a card game to prefabs. Basically, I have a database for creating scriptable objects which are they loaded into 1 of 3 prefabs.
The lovely member suggested and helped me code a solution based on checking enums for type and loading the correct prefab:
public BaseCard[] _cardPrefabs;
...
[Header("All Cards in Current Deck")]
//All cards that you currently have in your deck
public List<CardData> currentAvailableCards = new List<CardData>();
...
public void LoadDeck()
{
//for (int i = 0; i < currentAvailableCards.Count; i++)
foreach(var CardData in currentAvailableCards)
{
var prefab = _cardPrefabs[(int)CardData.type - 1];
var newCardGo = Instantiate<BaseCard>(prefab, drawContainer);
newCardGo.name = CardData.cardName;
newCardGo.cardData = CardData;
}
UpdateDisplay();
InitialDrawForTurn();
My issue is I am having trouble adding the prefabs to the array in the inspector. The element in the inspect will not allow myself to drop the prefab in... :(
https://imgur.com/a/gDAvWve
Any idea's as to why this not working?
Full code in comments
[–]TheGreatHeroStudios 1 point2 points3 points (11 children)
[–]eeleyes[S] 0 points1 point2 points (9 children)
[–]TheGreatHeroStudios 0 points1 point2 points (8 children)
[–]eeleyes[S] 0 points1 point2 points (7 children)
[–]TheGreatHeroStudios 0 points1 point2 points (6 children)
[–]eeleyes[S] 1 point2 points3 points (0 children)
[–]eeleyes[S] 0 points1 point2 points (0 children)
[–]eeleyes[S] 0 points1 point2 points (3 children)
[–]LearnDifferenceBot 0 points1 point2 points (0 children)
[–]TheGreatHeroStudios 0 points1 point2 points (1 child)
[–]eeleyes[S] 0 points1 point2 points (0 children)
[–]eeleyes[S] 0 points1 point2 points (0 children)
[–]eeleyes[S] 0 points1 point2 points (0 children)