音ゲー制作手順書#1
- Amagirasu
- 7月7日
- 読了時間: 3分

こんにちは、アマギラスです。単刀直入にUnityで簡易的な音ゲー制作します!これをマネして制作し、アレンジさせることであなただけのクオリティーの音ゲーを簡単に制作することが出来ます!それではいってみましょう!
Unityのバージョンは、『6000.1.0f1』を使用します。この関係上、新システムInput System Packageの設定を行います!大事な部分や難しい部分は画像で貼ってありますので、参考にしてください!
目次
1 .音ゲー制作プロジェクトの作成と設定
2D (URP なし) テンプレートで新規プロジェクトを作成
Edit ▸ Project Settings ▸ Player ▸ Other Settings で Active Input Handling を Input System Package (New) のみに設定 (再起動必須)
Edit ▸ Project Settings ▸ Time → Fixed Timestep を 0.01 に変更 (判定精度向上のため)
Window ▸ Package Manager から Input System 1.14 を追加
2. フォルダ構成とアセットのインポート
Assets/
┣ Audio/ 楽曲ファイル (WAV/OGG)
┣ Prefabs/ ノートや UI プレハブ
┣ Resources/
┃ ┗ Charts/ 譜面 JSON
┣ Scripts/
┃ ┣ Core/
┃ ┣ Game/
┃ ┗ UI/
┗ Sprites/ 矢印、UI 画像
スペルミスに気を付けてください。
サンプル曲 を Assets/Audio に配置。
※楽曲は好きな物を設定していただいてOKです(但し著作権に引っ掛かる物は避けましょう。BPMが一定の物が望ましい)
3. シーンレイアウト
新シーン Game.unity を作成
Main Camera を Orthographic, Size=5
Canvas を作成し Screen Space - Camera に設定。Reference Resolution は 1280x720 で Scale With Screen Size。
レーンは UI Image で 4 本作り、中央付近に判定ラインを細い画像で表示。
AudioSource (GameObject "Music") に楽曲を設定し、Play On Awake はオフ。
4. 新 Input System の設定
Assets ▸ Create ▸ Input Actions → PlayerInput.inputactions
Action Map Gameplay を作成。下表の通りバインド。
Action | Type | Binding |
TapL | Button | Keyboard / A |
TapD | Button | Keyboard / S |
TapU | Button | Keyboard / K |
TapR | Button | Keyboard / L |
Generate C# Class をオン → 自動で PlayerInput.cs が生成。
5. ノート Prefab の実装
Sprites から矢印画像をシーンにドラッグ。
Add Component ▸ BoxCollider2D → Is Trigger オン。
Add Component ▸ Note.cs を作成し以下を貼付:
using UnityEngine;
public class Note : MonoBehaviour
{
public float speed; // 移動速度 (単位: u/s)
public int lane; // レーン番号 0‑3
bool judged;
void Update()
{
transform.Translate(Vector3.down * speed * Time.deltaTime);
if (transform.position.y < -6f && !judged) // 判定ライン外
{
judged = true;
TimingManager.Instance.Judge(this, TimingManager.JudgeType.Miss);
}
}
}
Prefab にして Prefabs/Note.prefab として保存。
6. タイミング管理 (TimingManager.cs)
TimingManagerスクリプトを作成し、以下のコードをコピペしてください。
using UnityEngine;
using System.Collections.Generic;
public class TimingManager : MonoBehaviour
{
public static TimingManager Instance { get; private set; }
public enum JudgeType { Perfect, Good, Miss }
[Header("判定タイミング (ms)")]
public float perfectMs = 30f;
public float goodMs = 80f;
AudioSource music;
float bpm; // 曲毎に設定
float offset; // 曲頭の無音等 (秒)
void Awake() => Instance = this;
void Start() => music = GameObject.Find("Music").GetComponent<AudioSource>();
public double SongTime => music.time - offset;
public void Init(float bpm, float offset)
{
this.bpm = bpm;
this.offset = offset;
}
public JudgeType CheckHit(double noteBeat)
{
double currentBeat = SongTime / 60d * bpm;
double diffMs = Mathf.Abs((float)((noteBeat - currentBeat) * 60000d / bpm));
if (diffMs <= perfectMs) return JudgeType.Perfect;
if (diffMs <= goodMs) return JudgeType.Good;
return JudgeType.Miss;
}
public void Judge(Note note, JudgeType type)
{
// TODO: スコア計算, エフェクト
Destroy(note.gameObject);
}
}
ここまで来たら後半戦です!Jsonファイルを作成しノートをスポーンさせる処理を行います。一先ず一旦休憩しましょう。お疲れさまでした。