LoginSignup
0
0

More than 3 years have passed since last update.

【Unity】インスペクターで指定したオーディオをマウスクリックで再生する方法(自分用)

Last updated at Posted at 2020-10-08
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestScript : MonoBehaviour
{
    AudioSource audioSource;

    public AudioClip sound;


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

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            audioSource.PlayOneShot(sound);
        }
    }
}

AudioSource型の変数とオーディオのデータを格納する変数をpublicで作る。
その後Getcomponentし、左クリック処理の中に

audioSource.PlayOneShot(sound);

を入れれば左クリックをしたらインスペクターで指定したオーディオが起動する。
以上。

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