top of page

音ゲー制作手順書#1

音ゲー制作手順書#1

こんにちは、アマギラスです。単刀直入にUnityで簡易的な音ゲー制作します!これをマネして制作し、アレンジさせることであなただけのクオリティーの音ゲーを簡単に制作することが出来ます!それではいってみましょう!

Unityのバージョンは、『6000.1.0f1』を使用します。この関係上、新システムInput System Packageの設定を行います!大事な部分や難しい部分は画像で貼ってありますので、参考にしてください!


目次


1 .音ゲー制作プロジェクトの作成と設定


  1. 2D (URP なし) テンプレートで新規プロジェクトを作成

  2. Edit ▸ Project Settings ▸ Player ▸ Other Settings で Active Input Handling を Input System Package (New) のみに設定 (再起動必須)

  3. Edit ▸ Project Settings ▸ Time → Fixed Timestep を 0.01 に変更 (判定精度向上のため)

  4. 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. シーンレイアウト


  1. 新シーン Game.unity を作成

  2. Main Camera を Orthographic, Size=5

  3. Canvas を作成し Screen Space - Camera に設定。Reference Resolution は 1280x720 で Scale With Screen Size

  4. レーンは UI Image で 4 本作り、中央付近に判定ラインを細い画像で表示。

  5. AudioSource (GameObject "Music") に楽曲を設定し、Play On Awake はオフ。


4. 新 Input System の設定

  1. Assets ▸ Create ▸ Input Actions → PlayerInput.inputactions

  2. Action Map Gameplay を作成。下表の通りバインド。

Action

Type

Binding

TapL

Button

Keyboard / A

TapD

Button

Keyboard / S

TapU

Button

Keyboard / K

TapR

Button

Keyboard / L

  1. Generate C# Class をオン → 自動で PlayerInput.cs が生成。


5. ノート Prefab の実装


  1. Sprites から矢印画像をシーンにドラッグ。

  2. Add Component ▸ BoxCollider2D → Is Trigger オン。

  3. 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);
        }
    }
}
  1. 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ファイルを作成しノートをスポーンさせる処理を行います。一先ず一旦休憩しましょう。お疲れさまでした。


最新記事

すべて表示
個人開発ゲーム制作者の「あるある」20連発

こんにちは、アマギラスです。個人でゲーム開発をしているとふとしたタイミングでアイデアが思い浮かんだり、途端にやる気がなくなったり、嫌気がさしたり…色々ありますよね? そんなあるあるを20個ほどご用意しました。個人開発ゲーム制作者の「あるある」20連発少しでも共感していただけ...

 
 
bottom of page