码迷,mamicode.com
首页 > 编程语言 > 详细

Unity常用音频操作类

时间:2021-07-21 17:40:35      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:pre   设置   collect   upd   ali   net   链接   ati   sys   

using UnityEngine;
using System.Collections;
 
public class AudioPlay : MonoBehaviour {
    public static AudioPlay Instance;
    public AudioClip[] FuChuAudio;
    public AudioSource FCAudio;
   // public AudioSource BabyAudio;
    // Use this for initialization
    void Awake()
    {
        Instance = this;
    }
 
    void Start () {    
    }
    
    // Update is called once per frame
    void Update () {    
    }
    /// <summary>
    /// 播放某个音频
    /// </summary>
    /// <param name="i"></param>
    public void playAudio(int i)
    {
        FCAudio.clip = FuChuAudio[i];
        FCAudio.Play();
    }
    /// <summary>
    /// 停止播放所有的音频
    /// </summary>
    public void StopplayAll()
    {
    
        for (int i= 0; i< FuChuAudio.Length; i++)
        {
            FCAudio.clip = FuChuAudio[i];
            FCAudio.Stop();
        }      
    }
    /// <summary>
    /// 停止播放某个音频
    /// </summary>
    /// <param name="i"></param>
    public void StopplayOne(int i)
    {
        FCAudio.clip = FuChuAudio[i];
        FCAudio.Stop();
    }
 
    /// <summary>
    /// 循环播放某个音频
    /// </summary>
    /// <param name="i"></param>
    public void playLoop(int i)
    {
        FCAudio.clip = FuChuAudio[i];
        FCAudio.loop = true;//设置声音为循环播放 ;
        FCAudio.Play();
    }
}
————————————————
版权声明:本文为CSDN博主「记录成长分享」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lrh15980692010/article/details/76570423
/**
*将这个脚本挂载到一个空物体上,并且给它添加 AudioSource 组件
*/
using
System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> /// 控制所有音乐的管理类 /// </summary> public class AudioManager : MonoBehaviour { //将要轮流播放的音乐组 public AudioClip[] audioGroup; //当前播放的是谁 private int playingIndex; //是否允许播放音乐 private bool canPlayAudio; //AudioSource组件 private AudioSource audioSource; //----------------------------------------------------- void Start() { audioSource = this.GetComponent<AudioSource>(); canPlayAudio = true; playingIndex = 0; } //----------------------------------------------------- void Update() { if (canPlayAudio) { PlayAudio(); canPlayAudio = false; } if (!audioSource.isPlaying) { playingIndex++; if (playingIndex >= audioGroup.Length) { playingIndex = 0; } canPlayAudio = true; } } //----------------------------------------------------- private void PlayAudio() { audioSource.clip = audioGroup[playingIndex]; audioSource.Play(); } //----------------------------------------------------- } ———————————————— 版权声明:本文为CSDN博主「哟呵呵和」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/m0_37250299/article/details/79072361

 

Unity常用音频操作类

标签:pre   设置   collect   upd   ali   net   链接   ati   sys   

原文地址:https://www.cnblogs.com/qq2806933146xiaobai/p/15038743.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!