0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Unity】音を鳴らそう

Posted at

やりたいこと

 ・BGMをループ再生。
 ・SEを高頻度で再生。(一度止めてからもう一度再生?)

AudioClip と AudioSource

AudioClip
Unityで扱われる「音声データ」(ex. 音楽CD)
AudioSource
Unityで扱われる「AudioClipの再生状況等を管理するやつ」(ex.音楽プレイヤー)

リファレンス調査

 ・ループ再生はloop = trueにするだけで設定できる。楽だねぇ。

AudioSource audioSource;
audioSource = gameObject.AddComponent<AudioSource>();
audioSource.clip = Resources.Load("Sounds/1_3line") as AudioClip;
audioSource.loop = true;
audioSource.Play();

 ・SEの高頻度再生(シューティングのショットのような)は上記からloopを設定せずPlay()だけで可能。
  一度目の再生が完了するまで二度目の再生が待たされることはない。
  ただし、毎フレームだと音が再生されないため、
  最短でも2フレームに一度として再生する必要があるっぽい。

参考サイト

(AudioSource)[https://docs.unity3d.com/ja/2017.4/ScriptReference/AudioSource.html]

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?