Skip to content

Instantly share code, notes, and snippets.

@IshidaGames
Created November 23, 2019 06:52
Show Gist options
  • Save IshidaGames/257f2d6676a7b3078e35438dbc79188f to your computer and use it in GitHub Desktop.
Save IshidaGames/257f2d6676a7b3078e35438dbc79188f to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//オブジェクトにAudioSourceコンポーネントを追加
[RequireComponent(typeof(AudioSource))]
public class SE : MonoBehaviour
{
//音声ファイルを入れる
public AudioClip[] sound;
//AudioSourceコンポーネントを入れる変数
AudioSource audioSource;
void Start()
{
//AudioSourceコンポーネントを取得
audioSource = GetComponent<AudioSource>();
}
public void AttackSound()
{
//音声を鳴らす
audioSource.PlayOneShot(sound[0]);
}
public void DamageSound()
{
audioSource.PlayOneShot(sound[1]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment