9
12

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】GameObjectを非アクティブにする処理で、同時に流すSEが鳴らない問題解決メモ

Last updated at Posted at 2022-02-09

少し詰まったので備忘録として残しておきます。

ボタン押下時に、対象のGameObjectを非アクティブにする処理で、
ボタンのSEが鳴らない問題がありました。

原因としては、対象のGameObjectにAudioSourceが紐づいていたので、
非アクティブにすると音が鳴らなくなってしまうということでした。

##解決策

[SerializeField] AudioClip onButtonSE;
AudioSource audioSource;

void Start()
{
    audioSource = GetComponent<AudioSource>();
}

それ自体で音を鳴らすのではなく、別で用意したGameObjectにて音を鳴らすことで解決できました。

[SerializeField] AudioClip onButtonSE;
AudioSource audioSource;

void Start()
{
    audioSource = GameObject.Find("Speaker").GetComponent<AudioSource>();
}
9
12
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
9
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?