当前位置:网站首页>Project training - Design and development of 2D multiplayer fighting game based on unity (v. use audiomixer to control the volume)
Project training - Design and development of 2D multiplayer fighting game based on unity (v. use audiomixer to control the volume)
2022-04-22 19:05:00 【Xyxxi】
Catalog
One 、 Preface
In the process of game development , Plan to set up a global control volume gui Interface , At the same time, you can control the background music and other game special effects separately , So we used Audio Mixer solve
Two 、 step
1、 Create a volume adjustment panel UI
Created two sliders , Control the background music and sound effects of the game respectively , And set the default value of the slider bar value Set to 1

2、AudioSource How to play it
You can see ,AudioSource There are three ways to play
Play() Member method .
PlayOneShot( Parameters ) Member method .
PlayClipAtPoint(clip,position) Static methods .
3、 establish Audio Mixer
Use Audio Mixer Control the global volume , First, in the Groups Add members under :Music and SoundEffect( Game sound ), Drag the corresponding music to AudioClip after , take Music and SoundEffect Drag onto Audio Source Under components Output in
The hierarchical relationship is shown in the figure below , adopt MasterMixer Of Music To control the volume of background music , adopt SoundEffect To control the volume of the game

4、 Exposure parameters
Need to put Music and SoundEffect Parameter exposure of (Expose) come out , So we can control the volume through the code :
- First exposed Master Parameters of :
2. And then click Exposed Parameters, Choose what we just exposed Master Parameters of , Press down F2 Change the name to MasterVolume:
Related scripts :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
public class AudioManager : MonoBehaviour
{
public AudioMixer audioMixer; // controlled Mixer Variable
public void SetMasterVolume(float volume) // A function that controls the main volume
{
audioMixer.SetFloat("MasterVolume", volume);
// MasterVolume Exposed for us Master Parameters of
}
public void SetMusicVolume(float volume) // A function that controls the volume of background music
{
audioMixer.SetFloat("MusicVolume", volume);
// MusicVolume Exposed for us Music Parameters of
}
public void SetSoundEffectVolume(float volume) // A function that controls the volume of sound effects
{
audioMixer.SetFloat("SoundEffectVolume", volume);
// SoundEffectVolume Exposed for us SoundEffect Parameters of
}
}
5、 Adjust the volume
Set the maximum and minimum values of the slider to solve the problem , Make sure that the sound size range
3、 ... and 、 problem
The original sound effect of the game is that each object is added separately Audio Source, However , Want to use AudioMixer Adjust the , The track of each sound effect needs to correspond to , It can only be exact AudioSource Components , therefore , Static PlayClipAtPoint Method cannot be used by AudioMixer control
resolvent :
Create an empty object , Hang script , All the code and Clip Centrally manage... In this script , And change the previous playback method , Directly through instance The singleton object calls the corresponding method to play

meanwhile , Use the membership method , Every guarantee has one AudioSource Components , Make sure AudioMixer The volume can be adjusted correctly
版权声明
本文为[Xyxxi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221902144116.html
边栏推荐
- 每日AI前沿术语:绿色AI(Green AI)
- 运维工具那么多,选择哪个好? 跟着我3秒搞定
- 工商银行分布式服务C10K场景的解决方案
- AWSL!这波回忆杀真的爱了!
- With the rapid and savage growth of single chip microcomputer embedded industry, the demand of various posts also increases
- 数据库索引
- Some indicators in text classification
- 2019-11-19解决Go test执行单个测试文件提示未定义问题
- C -- database connection statement
- GB8624-2012 与GB8624-2006 有什么区别?
猜你喜欢

原来,这才是开发者打开世界读书日的正确姿势

Introduction to ribbon of microservice load balancer

leetcode151. Reverse the words in the string (thought + explanation)

Cvpr2022 𞓜 collaborative dual stream visual language pre training model for cross modal retrieval

Error c4996 'fopen': this function or variable may be unsafe Consider using fopen_ s instead. To disabl

JSP learning (IX. filter, wildcard and cookie processing)
![[self redemption -- top 101 4-day question brushing plan of niuke.com] warm up exercise on the first day](/img/31/8120f310af28e4cf49f67616748b7a.png)
[self redemption -- top 101 4-day question brushing plan of niuke.com] warm up exercise on the first day

可以惊艳你的登录网页

微服务负载均衡器Ribbon介绍

webrtc+turn+peerconnection_server测延时
随机推荐
Can amaze your login page
MySQL数据库中的索引(含SQL语句)
爱可可AI前沿推介 (4.22)
postgre创建序列并绑定到表字段
[appium stepping on the pit] could not proxy command to the remote server Original error: timeout of 240000ms exceeded
高德Flutter官方组件amap_flutter_map在地图上画圆
静态分派和动态分派
leetcode:642. Design search automatic completion system
Will map () in JS change the original array
RHCE-ansible
Type of Flink window
[network security] duomics variable coverage vulnerability from white box test to actual combat
mysql查询带序列号
如何写一篇五彩斑斓的博客.append(可爱)
VS 2022 安装vld内存泄漏检测工具
Some problem records using rectclerview
[Luogu] p2372 yyy2015c01 challenge perimeter (BFS)
What is the difference between gb8624-2012 and GB8624-2006?
transfer方法详解
Mysql索引