找回密码
 立即注册
查看: 425|回复: 0

[笔记] 开发h5小游戏,Unity 音效的播放与音量的调节

[复制链接]
发表于 2021-12-13 10:03 | 显示全部楼层 |阅读模式
开发h5小游戏,Unity 音效的播放与音量的调节实现的相关代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioManager : MonoBehaviour
{
    public static AudioManager instance { get; set; }

    private AudioSource audioS;
   
    //音量
    public float volume;

    // Start is called before the first frame update
    void Start()
    {
        instance = this;
        audioS = GetComponent<AudioSource>();
        audioS.volume = volume;
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void AudioPlay(AudioClip clip)
    {
        audioS.PlayOneShot(clip);
    }
}空对象挂载AudioSource组件
需要播放音效的脚本
循环播放不同音效
声明部分
//音效
public AudioClip[] clips;

//音效标记
public static int clippointer=0;播放部分
//播放音效
AudioManager.instance.AudioPlay(clips[clippointer]);

//循环播放不同的音效
if (clippointer < 3)
    clippointer++;
else
    clippointer = 0;以上就是 开发h5小游戏,Unity 音效的播放与音量的调节实现的相关代码,更多内容欢迎关注之后的文章
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-12 16:41 , Processed in 0.087265 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表