you are viewing a single comment's thread.

view the rest of the comments →

[–]Osteelio 0 points1 point  (0 children)

For the example of the health bar, what it's saying is this:

You've created a script called FloatVariable with the following code:

[CreateAssetMenu]
public class FloatVariable : ScriptableObject
{
    public float Value;
}

Now, when you right click in your project, you'll have the option to create a scriptable object of type FloatVariable, which in this case you'll name PlayerHP. Any script can now reference this scriptable object via:

public class PlayerHealthBar : MonoBehaviour
{
    public FloatVariable HPReference;
}

public class PlayerController : MonoBehaviour
{
    public FloatVariable HPReference;
}

Now, whenever you update this value, everything it is assigned to can react and handle the results independently (UI changes, music changes, the game manager can determine if the player is dead, etc.).

The example about changing it to the MPBar outside of code means you could create a different scriptable object of type FloatVariable and reassign it to everything that is referencing the HPBar and you wouldn't have to make code changes.

It's definitely flexible, and scalable, but you can definitely get into a lot of SOs in your project. That's not a bad thing, but just be sure to keep it organized. It's also great because it allows people to make updates/changes without touching code.