This looks like a job tailor made for ScriptableObjects!
ScriptableObjects are basically structured blobs of predefined data to help you create content for your game.
For instance if I had a ScriptableObject called Weapon, it might have these properties:
- name
- detailed name
- description
- damage
- toughness
- weight
- what it looks like in the inventory
- what model it uses in game
- what animations the player uses to swing it
I would create many of these Weapons, each one a file on disk (also called an “asset”), with different properties. I might have Sword, Longsword, Shortword, Dagger, Knife, etc.
Could also break it into EdgedWeapons and RangedWeapons for instance.
And tell you what, just because it’s a Wednesday night, I am giving away a brand-new ScriptableObject just for you:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu]
public class MeleeWeapon : ScriptableObject
{
public string Description; // such as "Longsword"
// how much it deals per hit
public int damage; // such as 4hp
// or perhaps:
public string damageDice; // such as 2d6+4
public Sprite inventorySprite;
public GameObject Prefab; // what gets attached to the player's hand
// add any other attributes here... magic, durability, weight, etc
// level requirements, attack speed, etc.
}
Make a script called MeleeWeapon.cs and stick the above code into it.
When Unity finishes compiling, make a folder and then inside that folder right-click and Create → Melee Weapon.
Congratulations, you just made your first ScriptableObject, fully editable in Unity. Now go nuts!