Today I decided to just create a simple gridbased SRPG map project for practice. I was mostly looking at games like Fire Emblem for reference, and started creating units on a grid that I could select and move around.
I started looking at ways to set up stats for units on the map and thought ScriptableObjects would be a good thing to use for certain properties that will never change on runtime. So for example:
public class UnitAttributes : ScriptableObject
{
[SerializeField]
private string unitName;
[SerializeField]
private Sprite portrait;
[SerializeField]
private int movement;
}
I have a UnitInstance prefab with an attached MonoBehaviour script like this:
public class UnitInstance : MonoBehaviour
{
[SerializeField]
private UnitAttributes attributes;
private void Awake()
{
}
}
At first I just attached a UnitAttributes asset I created on the editor for an existing UnitInstance game object on the scene which works fine.
However, if I wanted dynamically put units on the map via UI at runtime with different UnitAttributes asset, what’s the best way to set the “attributes” field in the MonoBehaviour script?
Basically for now I’m just thinking of creating two buttons on the screen so that one will create a unit with X attributes while the other will create a unit with Y attributes on the map (X and Y would be assets of UnitAttributes I created beforehand).
So far I’ve seen Resources.Load but apparently that’s not a good way to do this? I’ve also seen mentions of AssetDatabase but not totally sure how this is used (seems like its similarly just going through folders?). Im thinking I dont understand SOs well enough but once again I’ve spent all day reading discussion topics about this and as a beginner its really hard to tell whats the best way to do something when lots of people are saying different things (and I can’t tell if some of them are suggesting bad practices or not).