Unityで音を再生する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class EventObjectSound : MonoBehaviour | |
{ | |
public AudioClip audioClip; | |
private AudioSource audioSource; | |
public void PlaySound () | |
{ | |
audioSource.Stop (); | |
if (audioClip && audioSource) { | |
audioSource.Play (); | |
} | |
} | |
public void PlaySoundOneShot () | |
{ | |
audioSource.Stop (); | |
if (audioClip && audioSource) { | |
audioSource.PlayOneShot (audioClip); | |
} | |
} | |
public void StopSound () | |
{ | |
audioSource.Stop (); | |
} | |
// Use this for initialization | |
void Start () | |
{ | |
audioSource = gameObject.GetComponent<AudioSource> (); | |
audioSource.clip = audioClip; | |
} | |
// Update is called once per frame | |
void Update () | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment