Create a small Unity project that uses ScriptableObject for:
- Storing configuration for different weapon types (damage, attack speed, name, icon).
- Replacing a singleton — a global player score storage accessible from any scene and any script without a
static Instance. - Integration — weapons increase the score through the global storage.
- Create
WeaponSOScriptableObject
Fields:weaponName(string),damage(int),attackSpeed(float),icon(Sprite),prefab(GameObject — reference to a visual weapon model). - Create
GlobalScoreSOScriptableObject
Fields:score(int).
Methods:AddScore(int value),ResetScore(). - Create several weapon assets via
Create → Game/Weapon:- Sword (damage=10, attackSpeed=1.0)
- Bow (damage=7, attackSpeed=1.5)
- Staff (damage=15, attackSpeed=0.8)
- Create
WeaponPickupscript (MonoBehaviour)- Has a public field
WeaponSO weaponData. - In
OnTriggerEnter(or on click) when picking up the weapon:- Logs to the console: "Picked up {weaponName}, damage {damage}".
- Adds the weapon's damage to the global score:
GlobalScoreSO.AddScore(weaponData.damage). - Destroys the scene object.
- Has a public field
- Create
ScoreUIscript (MonoBehaviour)- Reference to
GlobalScoreSO. - In
Update()(or via an event) updates a UI Text field:Score: {score}.
- Reference to
- Scene setup:
- Place 3 different pickup items on the scene (prefabs or simple cubes with colliders).
- Assign each its own
WeaponSO(Sword, Bow, Staff). - Add a simple UI Text to display the score.
- Put
ScoreUIandGlobalScoreSOon an empty GameObject.
- Verify singleton replacement
- Ensure there is no
public static GlobalScoreSO Instanceanywhere. - Instead, the reference to
GlobalScoreSOis manually dragged into the Inspector of any script that needs the score.
- Ensure there is no
- Picking up a sword increases the score by 10.
- Picking up a bow increases it by 7, etc.
- When reloading the scene (or moving to a new scene), the score does NOT reset automatically (unless you call
ResetScore()). - All weapon configurations live in separate
.assetfiles and can be changed without rewriting code.
- Add a
WeaponEventSO(another ScriptableObject) as an event channel. When a weapon is picked up, it fires an event, andScoreUIlistens to it — thenScoreUIdoesn't need anUpdate()call every frame. - Create a "Reset Score" button that calls
GlobalScoreSO.ResetScore().