質問編集履歴
1
補足情報に修正案を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -159,3 +159,64 @@
|
|
159
159
|
|
160
160
|
Unity 2021.3.15f1
|
161
161
|
|
162
|
+
|
163
|
+
2023/5/8 追記
|
164
|
+
原因はわかっていませんが、下記のようにして実現したいことは達成しました。
|
165
|
+
```
|
166
|
+
using System.Collections;
|
167
|
+
using System.Collections.Generic;
|
168
|
+
using UnityEngine;
|
169
|
+
using UnityEngine.EventSystems;
|
170
|
+
|
171
|
+
public class SoundManager : MonoBehaviour
|
172
|
+
{
|
173
|
+
//--シングルトン始まり--
|
174
|
+
public static SoundManager instance;
|
175
|
+
|
176
|
+
private void Awake()
|
177
|
+
{
|
178
|
+
if (instance == null)
|
179
|
+
{
|
180
|
+
instance = this;
|
181
|
+
DontDestroyOnLoad(this.gameObject);
|
182
|
+
}
|
183
|
+
else
|
184
|
+
{
|
185
|
+
Destroy(this.gameObject);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
//--シングルトン終わり--
|
189
|
+
|
190
|
+
[SerializeField]
|
191
|
+
private AudioSource source;
|
192
|
+
|
193
|
+
[SerializeField]
|
194
|
+
private AudioClip revealTileSound; //音源データ1
|
195
|
+
|
196
|
+
[SerializeField]
|
197
|
+
private AudioClip flagTileSound; //音源データ2
|
198
|
+
|
199
|
+
[SerializeField]
|
200
|
+
private AudioClip revealBombSound; //音源データ3
|
201
|
+
|
202
|
+
[SerializeField]
|
203
|
+
[Range(0f, 1f)]
|
204
|
+
private float soundVolume = 0.3f;
|
205
|
+
|
206
|
+
public void PlayRevealTileSound()
|
207
|
+
{
|
208
|
+
source.PlayOneShot(revealTileSound, soundVolume);
|
209
|
+
}
|
210
|
+
|
211
|
+
public void PlayFlagTileSound()
|
212
|
+
{
|
213
|
+
source.PlayOneShot(flagTileSound, soundVolume);
|
214
|
+
}
|
215
|
+
|
216
|
+
public void PlayRevealBombSound()
|
217
|
+
{
|
218
|
+
source.PlayOneShot(revealBombSound, soundVolume);
|
219
|
+
}
|
220
|
+
|
221
|
+
}
|
222
|
+
```
|