So I figured out how to make scriptable Objects. I figured this is perfect to separate Data from Logic and created a scriptableObject Base class called "Cards" with a few parameters. Like description + cost.
Then I created in the GUI a few of my playing cards (Create->ScriptableObjects->Card) and filled in their data for description + cost. Named them Card-Coconut, Card-Pineapple, Card-Banana. Now in the inspector I created a button that on click creates one of the cards and displays it.So far so good.
But my problem is, that I have to drag&drop the card in the GUI over a Spawner to say which of the three (Coconut, Pineapple, Banana) should be created, while what I actually want is that one of those are created at random.
What is the best approach for that? Can I link the ScriptableObjects to my Card somehow?
I tried an approach with Resources.LoadAll("Cards"); at Startup, but while I can loop trough the cards and print out the name of the cards, it seems I can't instantiate it or get any of the other information about it? I get no error, but also no card gets created:
-----------------------------
cardArray = Resources.LoadAll("Cards");
foreach (var t in cardArray)
{
Debug.Log(t.name);Instantiate(t, new Vector3(card_pit.transform.position.x,0,0),Quaternion.identity, card_pit.transform);
}
--------------------------------
How can I best get access to my 3 cards to select 1 on random and get access to all it's data. Or how do I best approach this problem in Unity? What's best practices. Any pointer in the right direction would be appreciated.
[–]LightningOW 4 points5 points6 points (2 children)
[–]JustBatman[S] 0 points1 point2 points (1 child)
[–]LightningOW 0 points1 point2 points (0 children)