I have created a Scriptable Object with [CreateAssetMenu] option in the editor and it’s called ‘Assets/MyCard1.asset’. In there, I have specified some values like name, sprite, attack, health etc.
So my goal is to spawn a deck of 30 cards based on the same Prefab, but when I use ‘Instantiate(gamobject)’, it spawns a gameobject with default Prefab parameters. How do I assign ‘Assets/MyCard*.asset’ data to EACH of newly spawned cards (with code)? I can do that with Inspector just fine by dragging Asset to the Prefab’s script component.*
[CreateAssetMenu(fileName = “New Card”, menuName = “Card”)]
public class CardScriptable : ScriptableObject
{
public new string name;
public string description;
public Sprite artwork;
public int manaCost;
public int attack;
public int health;
}
public class SpawnStuff : MonoBehaviour
{
public GameObject myPrefab;
GameObject[] tempKarta = new GameObject[30];
void Start()
{
for (int i = 0; i < 30; i++)
{
tempKarta = Instantiate(kartonka);
temp.Karta*. ?? DRAW_DATA_FROM “Assets/MyCard1.asset” (); // ??
_}*_
}
}
Is my approach rational? If not, what is a better approach to this?