1
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 1 year has passed since last update.

【Unity】AudioSource の実装を簡潔に書けるメソッドチェーン

Last updated at Posted at 2022-11-20

概要

Unity の AudioSource の実装を簡潔に書けるメソッドチェーンを作りました。

サンプル

    [SerializeField] AudioSource audioSource;
    [SerializeField] AudioClip[] clips;

    public void Play()
    {
        // 優先度と最大距離を変更
        audioSource.SetPriority(16).SetDistance(500)
            // クリップ・音量・ピッチをランダムに変更
            .SetClip(clips).SetVolume(0.95f, 0.05f).SetPitch(1f, 0.1f)
            // 1秒遅れで再生
            .Play(1f);

        // クリップ・音量・ピッチ・遅延 をまとめて設定して再生
        audioSource.Play(clips, 0.95f, 0.05f, 1f, 0.1f, 1f);
    }

コード

1
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
1
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?