Skip to main content

Using Kassets' ScriptableObject Instances

Usage on MonoBehavior Script

Create a MonoBehavior Script and add Kassets' instance as a serialized field.

Player.cs :

Screen Shot 2020-11-16 at 20 47 36 copy

HealthBarUI.cs :

Screen Shot 2020-11-16 at 21 06 10 copy

Drag and drop PlayerHealth (FloatVariable) to Player's Health field :

Screen Shot 2020-11-19 at 6 25 46

Drag and drop PlayerHealth (FloatVariable) to HealthBarUI's Health field :

Screen Shot 2020-11-19 at 6 26 08

From example above, Player component's field Health and HealthBarUI component's field Health both refer to the same FloatVariable ScriptableObject instance PlayerHealth. Since both component refer to the same variable instance, the float value they refer to is shared. Each component then manage their own need with the value without any coupling between components. I.e. HealthBarUI doesn't have to request the Health value to Player component and Player component can manage its own Health without the need to distribute its value to other components.

Usage on UnityEvents

Kassets’s instance is a ScriptableObject asset. It can be referenced to UnityEvent via Inspector. You can aslo use dynamic method call on UnityEvent to pass a parameter.

UnityEvent

UnityEventDynamic