I've been trying to learn more about scriptable objects because I've heard they're quite useful, however, I'm still a bit confused about how to work with them since it seems to conflict with the try to decouple your code. From my understanding, you want to try and limit the times you reference scripts since this causes things to become dependent, but with scriptable objects, it seems like you're supposed to reference them.
Here's my scriptable object
public class PlayerInfo : ScriptableObject
{
public float maxHealth;
public float health;
public float shield;
public BaseClass playerClass;
public List<BaseAbility> abilities;
public Controls controls;
}
I originally just had a health script that handled all of it, but now it just references the scriptable object and adjusts the values in it
public class HealthController : MonoBehaviour
{
public PlayerData playerData;
void Start()
{
playerData = GetComponent<Player>().playerData;
ClassSelectButton.OnClassSelected += SetMaxHealth;
}
public void SetHealth(float newHealth)
{
playerData.health = newHealth;
}
public void SetMaxHealth(BaseClass newClass)
{
playerData.maxHealth = newClass.health;
playerData.health = playerData.maxHealth;
}
public void Damage(float damageTaken)
{
if (playerData.shield > 0)
playerData.shield -= damageTaken;
else
playerData.health -= damageTaken;
if (playerData.health <= 0)
Kill();
}
}
So is this actually how you'd want to use scriptable objects or did I miss something? lol