Skip to content

Instantly share code, notes, and snippets.

@gremito
Created January 15, 2020 14:56
Show Gist options
  • Save gremito/cbd571fe097074444a6bcacdbceaf387 to your computer and use it in GitHub Desktop.
Save gremito/cbd571fe097074444a6bcacdbceaf387 to your computer and use it in GitHub Desktop.
複数ボイス再生スクリプト
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UnitychanVoice : MonoBehaviour
{
private AudioSource audioSource;
[SerializeField]
private List<AudioClip> audioClipList = new List<AudioClip>();
private int playId;
public int PlayId
{
set { this.playId = value; }
}
void Start()
{
playId = 0;
audioSource = gameObject.GetComponent<AudioSource>();
}
void OnGUI()
{
if(GUI.Button(new Rect(50, 300, 100, 100),"Voice Play"))
{
VoicePlay();
}
}
public void VoicePlay()
{
audioSource.clip = audioClipList[playId];
playId = (playId < audioClipList.Count-1) ? playId+1 : 0;
audioSource.Play();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment