Question by
kelloffsean · Mar 18 at 03:30 AM ·
prefabprefabsclassesprefab-instance
Using Prefab Information in a Class?
So I've been trying to take my prefabs and create a Class where I can Instantiate them in a way. I'm having trouble wrapping my head around Classes even though I've been looking at it constantly. I grabbed this bare bones script from another person but I can't seem to mold it to my uses so I've hit my wall.
public class Card
{
private CardType _type;
private GameObject _card;
public string assetName;
public int[] cardCost;
// public CardType Type { get { return _type; } }
public Card(CardType type, string name, Vector3 position, Quaternion rotation)
{
// cardCost = new int[x, y, z];
assetName = string.Format("Card_{1}_{0}", type, name); //Card_{1}_{0} would be the first card in type Spirit
GameObject asset = GameObject.Find(assetName);
if (asset == null)
{
Debug.Log("Asset '" + assetName + "' could not be found.");
}
else
{
_card = Instantiate(asset, position, rotation);
_type = type;
}
}
My prefabs look like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New Card", menuName = "Card")]
public class CardScriptable : ScriptableObject
{
public string cardName;
public string description;
public string type;
public Material cardMat;
public int mechCost;
public int natureCost;
public int spiritCost;
public int genericCost;
public int attack;
public int health;
}
Comment
Your answer
Follow this Question
Related Questions
Problems with instantiating 1 Answer
PrefabUtility.RevertPrefabInstance() not working 2 Answers
Polybrush won't save to prefab 1 Answer