I have been doing Unity tutorials for about two weeks now and I have made some very basic things. Sorry if this is a super simple question, but I have spent the last 5 hours working on this and decided to come here.
What I have done so far:
I have made a very basic card game, where cards have properties like Attack and Health. These values are stored in a ScriptableObject for each card.
[CreateAssetMenu(fileName = "New Card", menuName = "Card")]
public class Card : ScriptableObject
{
public int instanceNumber;
public bool isDefaultCard = false;
public string cardName;
public string description;
public string flavorText;
public Sprite cardArt;
public int manaCost;
public int health;
public int attack;
public int characterClass;
public void printCardData()
{
Debug.Log(cardName + ": " + description);
}
}
Now I also have a card prefab where on the Unity UI I can drag the prefab onto the scene and then drag my ScriptableObject into the Card Display Script and it updates the card and displays everything fine!
I can't for the life of me figure out how to do this with code though. I have no idea how to access my ScriptableObjects from code.
I understand I could instantiate a prefab with something like this:
Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity);
But how do I add my card data to it? I want the game to have rewards at the end of a battle that shows a random selection of cards each time and you pick one. So this means create 3 card objects that have a random ScriptableObject attached to them. But again, no matter what I try I can't seem to find anyway to access my ScriptableObjects from code.
Sorry again if this is super simple, but I am very lost. I need a way to create an object of any my ScriptableObjects cards at any time. The player will have many times to add more cards to their deck, but their deck will only have 20-30 cards at a time.