アイテムシステムは、SRPGの重要な要素です。
装備品と消費アイテムを管理すれば、戦略性が高まります。
この記事では、実装方法を詳しく解説します。
✨ この記事でわかること
- アイテムデータの設計
- 装備システムの実装
- 消費アイテムシステムの実装
- インベントリ管理の実装
- 実装例とコード

アイテムシステムは、まずデータ構造から設計しましょう。装備品と消費アイテムを分けて管理します。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
あなたのオリジナルゲーム、今年こそ完成させませんか?
RPG・アクション・ホラー…Unityで本格ゲームを作りたい人のための学習サイトです。
実際に完成するゲームを題材に、
ソースコード・素材・プロジェクト一式をすべて公開。
仕事や学校の合間の1〜2時間でも、
「写経→改造」で自分のゲームまで作りきれる環境です。
アイテムデータの設計

アイテムデータの設計は、システムの基礎です。
設計方法を紹介します。
アイテムデータ構造
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
using UnityEngine; [CreateAssetMenu(fileName = "NewItem", menuName = "SRPG/Item")] public class ItemData : ScriptableObject { [Header("基本情報")] public string itemName; public string description; public ItemType itemType; public int itemID; [Header("装備品")] public EquipmentSlot equipmentSlot; public int attackBonus = 0; public int defenseBonus = 0; public int speedBonus = 0; public int magicBonus = 0; [Header("消費アイテム")] public ItemEffect effect; public int effectValue = 0; public bool isConsumable = true; [Header("その他")] public int maxStack = 99; // 最大スタック数 public Sprite icon; } public enum ItemType { Equipment, // 装備品 Consumable, // 消費アイテム Key // キーアイテム } public enum EquipmentSlot { Weapon, // 武器 Armor, // 防具 Accessory // アクセサリ } public enum ItemEffect { Heal, // 回復 ManaRestore, // MP回復 Buff, // バフ Debuff // デバフ } |
このコードで、アイテムデータ構造が定義できます。
ScriptableObjectで管理すれば、デザイナーも編集できます。
アイテムの種類
✅ 基本アイテムの種類
- 武器:攻撃+10〜30、装備スロット:武器
- 防具:防御+10〜30、装備スロット:防具
- 回復薬:HP回復+50、消費アイテム
- MP回復薬:MP回復+30、消費アイテム
アイテムの種類を増やすことで、戦略性が高まります。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
装備システムの実装

装備システムは、装備品を管理します。
実装方法を紹介します。
装備管理システム
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
[System.Serializable] public class Equipment { public ItemData weapon; public ItemData armor; public ItemData accessory; } public class EquipmentSystem : MonoBehaviour { public Equipment equipment = new Equipment(); public bool EquipItem(Unit unit, ItemData item) { if (item.itemType != ItemType.Equipment) { Debug.Log("装備できないアイテムです"); return false; } // 既存の装備を外す UnequipItem(unit, item.equipmentSlot); // 新しい装備を装備 switch (item.equipmentSlot) { case EquipmentSlot.Weapon: equipment.weapon = item; break; case EquipmentSlot.Armor: equipment.armor = item; break; case EquipmentSlot.Accessory: equipment.accessory = item; break; } // ステータスを更新 UpdateStats(unit); Debug.Log($"{item.itemName}を装備しました"); return true; } public void UnequipItem(Unit unit, EquipmentSlot slot) { ItemData oldItem = null; switch (slot) { case EquipmentSlot.Weapon: oldItem = equipment.weapon; equipment.weapon = null; break; case EquipmentSlot.Armor: oldItem = equipment.armor; equipment.armor = null; break; case EquipmentSlot.Accessory: oldItem = equipment.accessory; equipment.accessory = null; break; } if (oldItem != null) { // インベントリに戻す unit.inventory.AddItem(oldItem, 1); UpdateStats(unit); } } void UpdateStats(Unit unit) { // 装備ボーナスを計算 int attackBonus = 0; int defenseBonus = 0; int speedBonus = 0; int magicBonus = 0; if (equipment.weapon != null) { attackBonus += equipment.weapon.attackBonus; } if (equipment.armor != null) { defenseBonus += equipment.armor.defenseBonus; } if (equipment.accessory != null) { speedBonus += equipment.accessory.speedBonus; magicBonus += equipment.accessory.magicBonus; } // ユニットのステータスを更新 unit.equipmentAttack = attackBonus; unit.equipmentDefense = defenseBonus; unit.equipmentSpeed = speedBonus; unit.equipmentMagic = magicBonus; } } |
このコードで、装備システムが実装できます。
装備品を装備すると、ステータスが更新されます。

装備システムは、装備スロットごとに管理しましょう。武器、防具、アクセサリを分けて管理します。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
消費アイテムシステムの実装

消費アイテムシステムは、アイテムの使用を管理します。
実装方法を紹介します。
アイテム使用システム
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
public class ItemUsageSystem : MonoBehaviour { public bool UseItem(Unit user, ItemData item, Unit target = null) { if (item.itemType != ItemType.Consumable) { Debug.Log("使用できないアイテムです"); return false; } if (target == null) { target = user; } // アイテムの効果を適用 switch (item.effect) { case ItemEffect.Heal: target.currentHP = Mathf.Min( target.currentHP + item.effectValue, target.maxHP ); Debug.Log($"{target.unitName}のHPが{item.effectValue}回復しました"); break; case ItemEffect.ManaRestore: target.currentMP = Mathf.Min( target.currentMP + item.effectValue, target.maxMP ); Debug.Log($"{target.unitName}のMPが{item.effectValue}回復しました"); break; case ItemEffect.Buff: // バフを適用 ApplyBuff(target, item.effectValue); break; case ItemEffect.Debuff: // デバフを適用 ApplyDebuff(target, item.effectValue); break; } // アイテムを消費 if (item.isConsumable) { user.inventory.RemoveItem(item, 1); } return true; } void ApplyBuff(Unit target, int value) { // バフ処理 // 実装は省略 } void ApplyDebuff(Unit target, int value) { // デバフ処理 // 実装は省略 } } |
このコードで、消費アイテムシステムが実装できます。
アイテムを使用すると、効果が適用されます。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
インベントリ管理の実装

インベントリ管理は、アイテムの所持数を管理します。
実装方法を紹介します。
インベントリシステム
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
[System.Serializable] public class InventorySlot { public ItemData item; public int quantity; } public class InventorySystem : MonoBehaviour { public List<InventorySlot> items = new List<InventorySlot>(); public int maxSlots = 20; public bool AddItem(ItemData item, int quantity) { // 既存のスロットを探す InventorySlot existingSlot = items.Find(slot => slot.item == item); if (existingSlot != null) { // スタック可能かチェック if (existingSlot.quantity + quantity <= item.maxStack) { existingSlot.quantity += quantity; return true; } } // 新しいスロットを追加 if (items.Count < maxSlots) { InventorySlot newSlot = new InventorySlot { item = item, quantity = quantity }; items.Add(newSlot); return true; } Debug.Log("インベントリが満杯です"); return false; } public bool RemoveItem(ItemData item, int quantity) { InventorySlot slot = items.Find(s => s.item == item); if (slot == null || slot.quantity < quantity) { Debug.Log("アイテムが足りません"); return false; } slot.quantity -= quantity; if (slot.quantity <= 0) { items.Remove(slot); } return true; } public bool HasItem(ItemData item, int quantity = 1) { InventorySlot slot = items.Find(s => s.item == item); return slot != null && slot.quantity >= quantity; } public int GetItemQuantity(ItemData item) { InventorySlot slot = items.Find(s => s.item == item); return slot != null ? slot.quantity : 0; } } |
このコードで、インベントリ管理が実装できます。
アイテムの追加、削除、所持数チェックができます。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
実装例:完全なアイテムシステム

ここまで解説してきた「装備システム」「消費アイテムシステム」「インベントリ管理」を、実際のゲーム内でどのようにまとめて扱うのかを示すのが、この実装例です。
SRPGでは、UI操作・戦闘処理・イベント処理など、さまざまな場所からアイテム操作が呼び出されます。
そのため、個別のシステムを1つの窓口クラスに集約しておくと、全体の管理が非常に楽になります。
CompleteItemSystemの役割
CompleteItemSystemは、アイテム関連の処理を統括する「ハブ」のようなクラスです。
直接ステータス計算や効果処理を行うのではなく、各専門システムに処理を委譲します。
この構成にしておくことで、後からシステムを差し替えたり、UIやAIから安全に呼び出したりできるようになります。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
using UnityEngine; public class CompleteItemSystem : MonoBehaviour { [Header("システム")] public EquipmentSystem equipmentSystem; public ItemUsageSystem usageSystem; public InventorySystem inventorySystem; public void OnItemEquip(Unit unit, ItemData item) { equipmentSystem.EquipItem(unit, item); } public void OnItemUse(Unit user, ItemData item, Unit target = null) { if (inventorySystem.HasItem(item, 1)) { usageSystem.UseItem(user, item, target); } else { Debug.Log("アイテムを持っていません"); } } public void OnItemObtain(ItemData item, int quantity) { inventorySystem.AddItem(item, quantity); } } |
このクラスを経由することで、装備・使用・取得といった操作を一貫したルールで扱えます。
初心者が押さえておきたい使いどころ
このCompleteItemSystemは、以下のような場面で呼び出すことを想定すると理解しやすくなります。
例えば、装備画面のUIボタンでは OnItemEquip() を呼び出します。
戦闘中のアイテム使用では OnItemUse() を経由し、所持チェックと効果処理を同時に行います。
宝箱やイベントでの入手処理では OnItemObtain() を使えば、インベントリ管理を意識せずに済みます。
「UIやイベントはCompleteItemSystemしか触らない」というルールを決めておくと、後から仕様変更があっても修正箇所を最小限に抑えられます。
応用・拡張のポイント
慣れてきたら、以下のような拡張をこのクラスに追加していくと、SRPGらしい作りになります。
たとえば、ターン消費の管理を追加し、アイテム使用時に行動回数を減らす処理を入れることができます。
また、マップ上で使用できるアイテムの場合は、射程や範囲チェックをここで行うのも有効です。
さらに、AI用のアイテム使用ロジックを追加する場合も、このクラスを経由させることで、プレイヤーと敵の処理を共通化できます。

このように、CompleteItemSystemは「今後の拡張を受け止める土台」として設計するのがポイントです。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
よくある質問(FAQ)

ここでは、SRPGのアイテムシステムを実装する際によく出てくる疑問について解説します。
数値設定や設計方針に迷ったときの目安として活用してください。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
あなたのオリジナルゲーム、今年こそ完成させませんか?
RPG・アクション・ホラー…Unityで本格ゲームを作りたい人のための学習サイトです。
実際に完成するゲームを題材に、
ソースコード・素材・プロジェクト一式をすべて公開。
仕事や学校の合間の1〜2時間でも、
「写経→改造」で自分のゲームまで作りきれる環境です。
まとめ

アイテムシステムは、まずデータ構造から設計しましょう。
装備品と消費アイテムを分けて管理します。
✅ 今日から始める3ステップ
- ステップ1:アイテムデータ構造を設計する(所要2時間)
- ステップ2:装備システムを実装する(所要3時間)
- ステップ3:インベントリ管理を実装する(所要2時間)
本格的にUnityを学びたい方は、Unity入門の森で実践的なスキルを身につけましょう。
あなたのペースで、少しずつ進めていけば大丈夫です。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる



コメント