【Unityゲーム作成講座2】アドベンチャーゲームの作り方#12(サウンドシステム①)【ゆっくり解説】
Summary
TLDRThis video script offers a detailed tutorial on implementing a sound system in a game. It guides viewers through creating an AudioManager script to manage volume levels for music, sound effects, and system sounds. The tutorial covers attaching an AudioSource component for background music, setting up sliders for volume control within Unity's UI, and writing functions to adjust and play sounds. It also discusses obtaining sound sources from royalty-free platforms like DOVA-SYNDROME and SoundEffect-Lab for battle and normal BGMs, as well as sound effects for various in-game actions. The script concludes with tips on smoothly transitioning between different music tracks for an enhanced gaming experience.
Takeaways
- 🎧 The video provides a tutorial on how to implement a sound system in a game.
- 🛠️ It begins by instructing viewers to create an 'Audio Manager' script attached to a main object for managing audio settings.
- 🔊 The script includes variables for master volume, sound effects volume, system sound volume, and music volume, all initialized to 1.
- 📐 The master volume is used to adjust the overall volume across four channels: SFX, system sounds, and music.
- 🔗 The tutorial explains how to protect these values from being changed externally by using properties.
- 🎵 For managing background music, the script uses an AudioSource component attached to a game object that is created and set as a child of the main object.
- 📹 The 'Awake' function, which runs once at the start of the game, is used to set up the AudioSource and attach it to a newly created game object.
- 🔄 The video also covers creating functions to adjust the volume of sound effects and system sounds, as well as the master volume.
- 📊 Unity's UI system is utilized to create sliders for adjusting volumes, which are scripted to interact with the 'Audio Manager'.
- 🔗 A 'System UI' script is created to manage the UI components, including a system canvas and volume sliders.
- 🎶 The tutorial mentions using royalty-free music from DOVA-SYNDROME for background music and sound effects from EffectLab for various in-game actions.
Q & A
What is the main topic of the video script?
-The main topic of the video script is about explaining how to implement a sound system in a game, including creating an AudioManager script and managing audio volumes.
What is the purpose of creating an AudioManager script?
-The AudioManager script is created to manage and control the audio settings within the game, such as adjusting the master volume, sound effects volume, system sounds volume, and background music volume.
How does the script handle the initial volume levels for different audio channels?
-The script initializes the volume levels with public float variables for master volume, sound effects volume, system volume, and music volume, all set to 1, which represents the maximum volume.
What is the role of the AudioSource component in the script?
-The AudioSource component is used to play music by attaching it to a game object. The script also includes a method to automatically generate a game object with an AudioSource component attached when the game starts.
How does the script ensure that the AudioManager instance is unique throughout the game?
-The script uses a singleton pattern for the AudioManager class, ensuring that there is only one instance of the AudioManager throughout the game's lifecycle.
What is the purpose of the 'Start' function in the script?
-The 'Start' function in the script is used to initialize the audio system, such as creating a game object with an AudioSource component and setting it up to play music.
How can the volume of the background music be adjusted?
-The volume of the background music can be adjusted by creating a function that changes the 'musicVol' variable and then sets the AudioSource volume to the product of 'musicVolPercent' and 'MasterVolumePercent'.
What is the function of the 'SetVolumeMaster' method in the script?
-The 'SetVolumeMaster' method is used to adjust the master volume by setting the 'MasterVolume' variable and then updating the AudioSource volume to reflect the new master volume setting.
How does the script handle the creation of sliders for volume control?
-The script creates sliders using Unity's UI system, assigns them to control different audio channels, and links their values to the corresponding volume variables in the AudioManager script.
What is the purpose of the 'PlayClipAtPoint' function mentioned in the script?
-The 'PlayClipAtPoint' function is used to play a sound effect at a specific location in the game world by utilizing the position of a transform and the volume settings.
How does the script manage the transition between different background music tracks?
-The script plays a new music track by attaching it to the dedicated AudioSource for music. It suggests a future improvement to fade out the current music track and fade in the next one for a smooth transition.
Outlines
🎧 Audio System Implementation
The script introduces the process of implementing an audio system in a game. It begins by suggesting the creation of an 'Audio Manager' script attached to a main object. The script includes variables for master volume, sound effects volume, and music volume, all of which are adjustable. The tutorial also covers the automatic attachment of an AudioSource component to a game object and the use of the Awake function to initialize audio settings. Additionally, it explains how to create functions for adjusting the volume of sound effects and system sounds, and how to link these functions to sliders for user control.
🛠 Building the System UI for Volume Control
This paragraph details the creation of a user interface for system settings, specifically for volume control. It describes the process of making a button and a panel in Unity's UI system, naming them appropriately and setting up the panel for transparency and visibility. The tutorial then guides through adding sliders for master volume, music, sound effects, and system sounds within the panel. It explains how to set initial values for the sliders and how to link them to the previously created volume adjustment functions in the script. The paragraph also covers creating a script to manage the system UI, attaching it to the main object, and ensuring the UI updates correctly with the volume settings.
🔊 Implementing Singleton Pattern for AudioManager
The speaker discusses the implementation of the singleton pattern for the AudioManager class to ensure there is only one instance throughout the game. They explain the concept of a static variable that points to a single instance and provide a brief overview of how singletons work in game development. The tutorial includes steps to initialize the AudioManager instance correctly during scene changes and emphasizes the importance of writing code that is always in motion, rather than getting stuck. It also touches on the process of attaching audio sources to the AudioManager and adjusting the volume using sliders, which is crucial for the game's audio system.
🎵 Acquiring and Setting Up Audio Sources
The paragraph focuses on acquiring audio sources for the game, mentioning the use of royalty-free music from specific composers and sound effect labs. It details the process of downloading background music (BGM) for different game states, such as combat and normal gameplay, and sound effects for actions like attacking or button presses. The tutorial then explains how to import these audio files into Unity, organize them into an 'Audio' folder, and attach them to the AudioManager for use within the game.
📡 Playing Audio Clips and Managing BGM Transitions
This section covers the functionality of playing audio clips and managing background music within the game. It explains how to create functions to play system sounds and sound effects using the AudioSource component and how to adjust their volume based on the master volume and individual settings. The tutorial also addresses the playing of music by attaching different audio clips to a dedicated AudioSource and provides a method to avoid resetting the music clip upon entering different game states. The speaker plans to create a smooth transition between different BGM tracks in the next part of the tutorial.
Mindmap
Keywords
💡Audio System
💡Audio Manager Script
💡Volume Control
💡Audio Source Component
💡Unity
💡BGM (Background Music)
💡Sound Effects
💡UI (User Interface)
💡Singleton Pattern
💡Audio Clips
Highlights
Introduction to the method of implementing a sound system in a game.
Explanation on creating an 'Audio Manager' script attached to the main object.
Setting up float variables for volume control, including 'Master Volume Percent'.
Creating a function to adjust the volume of BGM, SFX, and system sounds.
Automatic attachment of the AudioSource component to a game object.
Introduction of the Awake function for initializing game system constructions.
Creating a game object and attaching an AudioSource component for music.
Adjusting the volume of BGM using a parameter in the script.
Building functions to adjust the volume of SFX and system sounds.
Creating sliders in Unity for volume control.
Scripting to manage the opening and closing of the system UI panel.
Explanation of the singleton pattern for the AudioManager class.
Using delegates for slider value change events.
Acquiring music and sound effects from various sources for the game.
Creating functions to play system sounds and sound effects.
Implementation of music playback with consideration of volume levels.
Adjusting the game's audio system to avoid abrupt music changes.
Preview of next episode's content focusing on smooth music transitions.
Transcripts
みなさんこんにちは happy
sunrise のゆっくり霊夢です今回
はサウンドシステムの導入の仕方について
解説していきます今回の作業内容の
プロジェクトファイル及び参考にさせて
いただいた動画の url は概要欄に
貼ってありますというわけで早速レッツ
ゴー
早速始めて以降今回はオーディオシステム
をつくってゲーム内におとう鳴らす仕組み
を解説するよ有無まず何すりゃいいんだ
まずはスクリプトを作ろう
オーディオマネージャーというスクリプト
作ってオーディオマネージャー
ほいそのスクリプトをメインオブジェクト
にアタッチして
ほいじゃあそのスクリプト開いて入らない
中身決してまずは音量を調節する仕組み
から作るよ音量を表すフロート変数を用意
しよう public float 変数
名はマスターボリュームパーセント
マスターボリュームパーセント初期値は
とりあえず1とかにしておこう=1 f
この値が1の場合は音量 max 例の
場合はミュートになる付6ふむ次は効果音
の音量変数名は sfx ボリューム
パーセント sfx ってなんだサウンド
エフェクトの約なるほど public
float sfx ボリューム%=1次
はシステム音木鶏 public
float システムボリューム%=1
最後に bgm public float
music vol %=1音量調節は
以上の4チャンネルに分ける下の3つの
音量にマスター音量を掛け合わせることで
全体の音量を調節できるようにするよう
ふむふむ一応この値を外から勝手に変え
られないようにプロパティで保護しよう
次は bgm を管理するための
コンポーネントを用意するオーディオ
ソースというコンポーネントに音声
クリップを当てはめれば音楽を流すことが
できるじゃあユニティーに戻って
オーディオソースをゲームオブジェクトに
アタッチし俺止まった今回はその作業も
スクリプト内で自動的に行うそんなこと
できるのかオーディオソース型の変数作っ
て変数名はミュージックそうすぱぶりっく
は要らないオーディオソースミュージック
ソースではゲーム開始と同時にオーディオ
ソースコンポーネントがータッチされた
ゲームオブジェクトを生成しそれをメイン
オブジェクトの子にする処理を書こうその
仕組みはウェイク関数に各アウェイク関数
過去のシリーズの中では初登場かなあ
ウェイク関数はゲーム開始と同時に一度
だけ実行される関数だ4つたと関数よりも
前に実行されるんだったかそうだから
ゲーム内のキャラのパラメーターの初期化
とかとは違ってゲームのシステムの構築の
ための処理などを書くまあ明確なルールが
あるわけじゃないからどっちでもいいんだ
けどねまず何を書けばいいまずは新規の
ゲームオブジェクトを生成する処理ゲーム
オブジェクト
ニューミュージックソース=ニューゲーム
オブジェクトmusic 総数これで
ミュージックソースという名前のゲーム
オブジェクトがヒエラルキー常に作られる
ふむふむミュージック総数 at
コンポーネントオーディオ総数これでこの
オブジェクトにオーディオソースがー
タッチされたふむそれと同時に
ミュージックソースにコンポーネントを
代入しよう music そう水=
なるほど最後にこのゲームオブジェクトを
メインオブジェクトの子に設定するニュー
ミュージックソーストランスフォーム
ペアレント=トランスフォーム
これで1回動かしてどうなるか見てみよう
をメインオブジェクトの下にミュージック
ソースって名前のオブジェクトが生成され
たそしてそのオブジェクトにオーディオ
ソースコンポーネントがアタッチされて
いるな成功だねこのオーディオクリップと
いう枠の中に音声データをアタッチして
再生すればこのゲームオブジェクトのある
位置からおとう鳴らすことができる今回の
ゲームは3 d じゃないから意味ない
けどな今回のゲームで使うのはこの
ボリュームというパラメーターだけだね
スクリプトでこの値を動かして bgm の
音量を調節するというわけで次は音量調節
関数を作ろうちょっと待て今 bgm 用
のオーディオソースは用意したが効果音と
システム音にも同様にオーディオソースが
必要なんじゃないか効果音とシステム音は
長久手市に秒の単発の音だからわざわざ
オーディオソース用椅子必要はない単発の
おとう鳴らすだけならオーディオソース.
プレイクリップ at ポイントという
便利関数を実行すればいいだけはいえーい
まずは効果音のボリュームを調整する関数
から関数名はセットボリュームアンダー
バー sfx にしよう public
ぽいどセットボリュームアンダーバー
sfx 引数はフロートを1個変数名は
パーセンとフロートパーセント中身は超
単純 sfx ボリューム%=パーセント
音量はスライダーで調節できるようにする
スライダーの値をこの関数の引数に
当てはめれば自在に音量調節ができ
るってわけですふむ6次はシステム音の
ボリューム変更処理 public
void セットボリューム
システムフローとパーセントシステム
ボリューム%=パーセント次 bgm の
ボリューム public void
セットボリュームミュージックフロート
パーセント music vol %=
パーセントここではオーディオソースの
ボリュームの値もどう時に変更する必要が
ある music ソースポリューム=
music vol パーセントかける
マスターボリューム%ふむ最後にマスター
音量 public void セット
ボリュームマスター
マスターボリューム=パーセントここでも
オーディオソースのボリュームを変更する
ミュージックソースボリューム=
music vol パーセントかける
マスターボリュームパーセントよし今度は
スライダーを作るよユニティーに戻って
ホイ画面の右下にボタン作ってボタンの
名前はシステムキャンバスを右クリック
ui ボタンその後ボタンを画面右下に
移動うそのボタンの中の文字をシステムに
書き換える
システムこのボタンを押したらシステム
画面を開けるように使用画面のど真ん中に
パネルを用意してキャンバスを右クリック
ui パネル
そしてパネルをちょっと縮める
こんなもんかパネルが半透明だとちょっと
見づらいから色を濃くしてパネルの
イメージコンポーネントのカラーを
クリックアルファの値を100にするこれ
でよしパネルの名前はパネルアンダーバー
システムにしようパネルアンダーバー
システムこのパネルでは音量調節だけで
なく今後西武とかロードもできるようにし
ていく予定ですふむついでにさっき作った
ボタンはボタンアンダーバーシステムに
変えておこうボタンアンダーバーシステム
ではパネルの中にスライダー ui を
設置し用パネルを右クリック
ui スライダーそのスライダーを大体
ここらへんに移動させる
続いてこのスライダーの中にテキストを
追加スライダーを右クリック
ui テキストその敵須藤スライダーの左
端に寄せる
4
こんなもんかそのテキストの文字を
マスター音量と書き換えよう
文字が見切れたこういう時は
アレンジメントを中央揃えに指定ベスト
フィットにチェックを入れるこれでよし
ok そのスライダーの名前をスライダー
アンダーバーマスターにしておいて
スライダーアンダーバーマスターその
スライダーを3個複製してコントロール d
コントロール d コントロール d
それぞれ名前をスライダー sfx
スライダーミュージックスライダー
システムに変えて
そいつらをパネル内にきれいに並べてホイ
ホイ
ほい
そしてスライダーの中のテキストも
書き換える
なくもっと
000
なんか文字サイズが不揃いで不格好だなぁ
こういう時はテキストの max サイズ
を小さくしてあげればいい4つのテキスト
を同時選択してコントロールをしながら
テキストをクリック
そして max サイズの値を14に
しようこれで綺麗になったふむこの
スライダーコンポーネントのバリューと
いう値これはスライダーのハンドルが左端
に行くと0右端に行くと1になるこの値を
さっき作ったボリューム変更関数と連動さ
せるわけだなそういうことです角
スライダーのボリュームの値は全部市にし
ておこう
できたぜそしてこのパネルを表示にする
ではシステムパネルを管理するための
スクリプトを作ろうシステム ui と
いう名前のスクリプト作って
システム ui そいつをメイン
オブジェクトにアタッチして
スクリプト開いてさっき作ったシステム
関連のパーツ等をこのスクリプトにア
タッチしていくよチャーそのための枠を
作るぜ頼むぜーまずはネームスペースいう
神具ユニディエンジン ui システム
ボタン用の枠を作る public ボタン
ぽたんアンダーバーシステム次にパネル
public a 6オブジェクトパネル
アンダーバーシステム阻止て各種音量調整
スライダー public slider
slider アンダーバーマスター
スライダーアンダーバー music
スライダーアンダーバー sfx っっ
スライダーアンダーバーシステム
できた税化したぜではシステムボタンを
押したらパネルが開く仕組みを作ろうか
at リスナーを使ってボタンの押下を
感知する仕組みをつくってどうやるんだっ
けまずボタンが押されたかどうかを判定
するブール値を作るそうだったそうだった
ぶーるープッシュボタンシステム=
false そしてあっとリスナーを使っ
てボタンを押したと同時にこのプールを
ブルーに変えるだったなそうそうぽたん
アンダーバーシステム音 click at
リスナーラムダ演算子 pb システム=
true そしてフレームの最後に忘れず
に false に戻すそうしないと
ボタン1回押したらそれから毎フレーム
ボタン連打することになるからねできた
よしではアップデート関数内にボタンが
押されたらパネルを表示しパネルが押され
た状態で再度ボタンを押したらパネルを
表示にする処理書いて任せろもしボタンが
押されたら
パネルが表示されている場合はパネルを
表示にするパネルが表示ならパネルを表示
するできたぜではユニティーに戻って各
パーツをアタッチし抵抗
おい
ほい
ホイホイ
ホイホイってきたアーチャーちゃんと動く
かテストしてみよう
000
動いてるぜではこのスライダーと
ボリュームを連動させる処理を各幼稚
ステム ui スクリプトに戻ってホイ
まずはマスター音量のスライダーからこれ
も at リスナーだろうそうだけど
スライダーの場合ボタンとちょっと書き方
が異なるスライダー master on
バリューチェンジどうあっどリスナー本場
流チェンジどつまり値が変わったときに
実行される処理仮想つまりハンドルが動い
た時にこの格好の中に書かれた処理が実行
されるつまりセットボリュームマスター
関数だなそうということはここで
オーディオマネージャーを参照しなきゃ
いけないなというわけでオーディオ
マネージャーをシングルトンかしてここ
から参照できるようにしようシングルトン
って何って方はステート工藤 ai の
作り方動画の40分30秒あたりで解説し
てますとりあえずオーディオマネージャー
クラス開いたぜシングルトンの書き方覚え
てる忘れたぜそんじゃあ改めて説明する
まずはオーディオマネージャー方の
static 変数を用意する
public static オーディオ
マネージャーインスタンス static
変数はゲーム内に必ず1個しか実態が存在
しないたとえオーディオマネージャーが2
個以上あってもこのインスタンスという枠
はかならず共通の1個のオーディオ
マネージャーを指し示すこれ参照の概念が
わからないとピンと来ないだろうなピンと
こない方に必殺技を教えてあげようどんな
技だよくわからんけど動きゃいいと強引に
納得するお前の常套手段だな真面目な話
マジでこれでなんとかなりますし理解わー
とから追い付いてきますゲーム作りで一番
やっちゃいけないことは手が止まって1
カ所にとどまり続けてしまうことです
とにかく書いて動かしてみるを徹底し
ましょう本題に戻ろうウイ次はウェイク
関数内に降格
もしインスタンスが塗るじゃなければ自分
を抹消するもシーンスタンスが塗るなら
インスタンスに自分を代入するそして
シーン切り替え時に自分を抹消しない今回
のゲームではシーン切り替えを行わないの
で本来この文は不要だけど一応これが
シングルトンの書き方の一つですこれで
ゲーム開始から終了までの間
オーディオ manager .
インスタンスは常に2個以上にならず確実
に1個だけ存在する状態が保障される
インスタンスが一個しかないということは
どのインスタンスを参照するのか選ぶ必要
もないつまりオーディオ manager
.インスタンスを呼べばいつでもどこでも
共通のオーディオマネージャーにアクセス
できるってわけですすげー星一つ忘れちゃ
いけないのがウェイク分の下に書いたこの
オーディオソースの初期化処理これらは
インスタンスが null の時だけ実行
されるべき内容だからこうやって切り取っ
てここに貼り付けるこれでシングルトン家
官僚システム言う位に戻ってぽいてワーッ
とリスナーの中でボリューム調整処理を
書いていくわけですけどもが無駄演算子
だろういやスライダーの場合それだと
うまくいかないそうなのかなので今回は
降格 delegate 中括弧
のカッコの中に処理を書けばいい
delegate ってなんだ分の中に
関数を作りながら埋め込むような仕組みだ
よそれラムダ式と何が違うんだほぼ同じだ
よじゃあなんでラムダ式じゃダメなんだ魔
理沙君はい動けばいいんだお前もわかって
ないのかよってりゲートやラムダ式はまだ
勉強不足なのでもっといい書き方はあるか
もしれないですがとりあえず自分が知っ
てるか気かたで進めさせていただきます
チャーとりあえず処理を書く税頼む
オーディオ manager .
インスタンス
セットボリュームマスターカッコこの格好
の中にスライダーの値を入れればいいわけ
だがその値はどうやってるんだー
slider .ばいうで参照できる
スライダー master . value
同じ要領で他の3つのスライダーにも関数
設定してっ
ん
ん
voodoo
できたよしこれで音量調節システムは
出来上がったいよいよ応答鳴らすのかその
前に音源を調達しなきゃね音源ってどう
やって調達するんだてはちょっとお買い物
行く母が妹の私が普段使わせていただい
てる曲はすべてこのドーバーシンドローム
さんで調達してる無料で商用利用可能な上
にハイクオリティーな bgm が
てんこ盛りだよそいつはすげぇ今回調達
する bgm は2種類
戦闘用の bgm と通常時の bgm
ちなみに選曲はあらかじめしておいたよう
ずらしく用意がいいなまず戦闘 bgm と
して採用させていただいたのがこちら匠東
さん作曲の大決戦を前が普段から愛用し
てる曲だな非常に汎用性が高く
めちゃくちゃちょうどいい感じがすごく
ちょうどいいデビューが下手くそすぎて
作曲者さんが可哀想だちなみに
ダウンロードの仕方は超簡単仮面下の
ダウンロードボタンを押してダウンロード
ファイルボタンを押すだけ f 6
次に通常時の bgm として今回使用さ
せていただくのがこちらかまぼこ幸子さん
作曲
不穏な雰囲気この曲もワイルドマンで使わ
せてもらったな曲名通りすごい不穏な
雰囲気があってなおかつシュールな感じも
してお気に入りいては以上の2曲を
ダウンロードしてダウンロードしたぜ次は
効果音を手に入れようこちらの効果音ラボ
さんはかゆいところに手が届く無料の音源
を大量に取り扱ってらっしゃいますこの
サイトには死ぬほどお世話になってるな
冗談抜きでこのサイトなかったらこの
チャンネル積んだ誰かもしれないぐらいお
世話になっておりますてどんなおとう調達
するんだ今回は4種類まず攻撃したり攻撃
を食らったりした時の実施って音あとは
ボタンを押したときのお父さん種類ほど
オッケまず10知っておとう手に入れよう
このように効果音ラボさんはさまざまな
音源をカテゴリ別に並べてくれてる今回は
戦闘カテゴリの中のパンチの中から感じの
ものを選ぼう
なんかちょっと重たすぎるかなし他にも
まだまだあるよ
しっ
をこれがいいショーパンチちょうどいい
コミカルさだじゃあこちらをダウンロード
次はボタンを押したときのシステム音か
ボタンで検索してみてそしたらズラって
候補が出てくるからこの中からいいのを
探そう目移りするナマズは一番
オーソドックスなボタンをクリックした時
のカチって音とりあえずボタン押すたびに
鳴らすならあんまり視聴強くない方がいい
な
これだいい感じに地味な音じゃあこれ
ダウンロード次は組み合わせが成功した時
や敵との戦闘に勝利したときなどいいこと
が起こったときに鳴らすプルリンってを
とっ
そして組み合わせが失敗したときなどの部
って音以上をダウンロードしてユニティー
に戻ろうただ今では手に入れた音源を
ユニティー内に取り込むオーディオという
フォルダを新しく作って
オーディオそしてその中に音源をドラッグ
ドロップ
ほいそしてそれぞれの名前を分かりやすく
支えてあげよう
ん
持っていません
ん
おっ
できたぜよしこれらの音源オーディオ
マネージャーにアタッチするよまずは2
種類の bgm の枠を作るパブリック
オーディオクリップ bgm アンダー
バーノーマルパブリックオーディオ
クリップ bgm アンダーバーバトル
ふむふむこんな感じであとはシステム音と
効果音の枠も作って了解
できたでは音源を当たっしよう
ん
アタッチしたぜオーディオマネージャーに
戻ってではおとう鳴らす関数を今から作っ
ていくよいいぞ最初に作るのはシステム音
を鳴らす関数
関数名はプレイシステムにしよう
public void プレイシステム
引数はオーディオクリップを1個音の
鳴らし方はいたって簡単オーディオソース
.プレイクリップ at ポイント引数は
3つ
右から音声クリップおとう鳴らす市の情報
最後に音量まずは音声クリップ次に位置
座標か今回のゲームでは市関係ないから
普通に減点座標でいいトランスフォー
home .ポジション最後に音量か音量
はシステム音量とマスター音量を
掛け合わせた数字システムボリューム
パーセントかけるマスターボリューム
パーセントでは早速おとうならしてみよう
メインクラス開いてメインクラスまずは
メインコマンドステートの最初に音を
鳴らしてみようこの state エンター
処理の最後にさっき作った関数を実行する
オーディオマネーじゃあインスタンス
プレイシステムオーディオマネージャー
インスタンスシステムクリックこれで
メインコマンドに移行するたびにカチって
音が鳴るわけかこの時くれぐれも
state エンター処理の格好の外に
書かないでねじゃないと毎フレーム
クリック音がなってしまうよ業界いっ
ちゃあ同じ処理を書くステートの最初に
書いていって次は敵と遭遇ステートの最初
おっ
その次は戦闘コマンド state
次は攻撃ステーとか攻撃 state で
はクリック音ではなく殴った音を入れる
から飛ばす
同様に敵からの攻撃 state も
飛ばす
的に勝利した state ここでは成功
したと機能等ならそうか
システムアンダーバーサクセス次
インベントリを開く state ここで
もクリック音鳴らす
さらにこの中では使うボタンが押された
タイミングでもおとうならそう
ここではステートの変化が無いからかそう
そう次アイテム組み合わせ state
このステートの最初にもクリック音を
鳴らす
そして組み合わせが成功したら成功音失敗
したら失敗音を鳴らす
ん
ん
続いて部屋の選択 state ここでも
クリック音を鳴らす
その次の部屋移動ステーとでも同様
次の何も見つからなかった state で
は失敗 on
アイテムを見つけた state では
成功音を鳴らす
これで1回動かしてみるかよしきたああ
あああ
となってる
なんかを通る生なじゃあ音量下げ8
スライダーもちゃんと機能してるいい感じ
だねでは同じ要領で効果音を鳴らす関数
作るよ仕組みはシステム音と全く同じ業界
public void プレイ
sound effects
オーディオソースプレイクリップ at
ポイントクリップ transform
ポジション効果音ボリュームかける
マスターボリュームよしじゃあ攻撃
state 内でこの関数実行しようまず
は自分から敵への攻撃 state
オーディオマネージャーインスタンス
プレイ sound effect
audio マネージャーインスタンス
sound effects アタック敵
からの攻撃する8でも同じものを書く
じゃあ再度テスト
4位
4
敵からの攻撃と自分の攻撃で音変えても
いいかもなあそこらへんは各自お好みで
調整してください一応成功だぜじゃあ最後
に bgm ならそうよっしゃー
public void プレイ
music
音楽に関しては専用のオーディオソースを
用意したからそのオーディオソースの
クリップっては国音源をアタッチして
プレイという関数を実行する music
ソースクリップ=クリップミュージック
そうスプレーではメインクラス開いて
メインコマンドステートに入った時点で
通常 bgm
敵との遭遇ステートに入った時点で戦闘 b
cm を鳴らそう
できたアーティスト
を音がなってううるせえええええちょっと
先に音量調節しよう
ちゃんとなってるがうん
おいメインステートに戻るたびに曲が
リセットされてしまうぞメインステートに
入るたびにクリップ入れ直してプレイ関数
実行するからだねもっと工夫しよう
もしアタッチしようとしてるクリップが
現在アタッチされてるクリップと同じだっ
たら何もせずに終了
これでいちいち途切れなくなるということ
でラスト
ん
goo
[音楽]
ん
goo
グー
ん
いい感じ敵と戦ってみよう
[音楽]
ちゃんと切り替わったなぁ敵を倒してみて
[音楽]
なんだか bgm の切り替わりが急
すぎるなそこなんですよ問題は今回はここ
で区切って続きは次回にしよう次回は再生
している bgm をゆっくりフェード
アウトさせるのと同時に次の bgm を
ゆっくりフェードインさせることで滑らか
に曲を遷移させる仕組みをつくるよう
楽しみだぜというわけで今回も最後までご
視聴ありがとうございましたもし
よろしければチャンネル登録お待ちして
おります次回も必ず見てくださいまたねー
5.0 / 5 (0 votes)