UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
AudioSource.pitch
# [AudioSource](https://docs.unity3d.com/cn/2019.4/ScriptReference/AudioSource.html).pitch public float **pitch** ; ## 描述 音频源的音高。 音高是一种让旋律更高或更低的品质。例如,请想象一下正在播放一个音高设置为 1 的音频剪辑。在播放该剪辑时,增加音高会使剪辑听起来更悠扬。类似地,将音高减小到 1 以下会使剪辑声音变得低沉。 ``` //Attach this script to a GameObject. //Attach an AudioSource to your GameObject (Click Add Component and go to Audio>Audio Source). Choose an audio clip in the AudioClip field. //This script sets the pitch of the audio at the start, and then gradually turns it down to 0 as time passes. using UnityEngine; //Make sure there is an Audio Source component on the GameObject [RequireComponent(typeof(AudioSource))] public class ExampleScript : MonoBehaviour { public int startingPitch = 4; public int timeToDecrease = 5; AudioSource audioSource; void Start() { //Fetch the AudioSource from the GameObject audioSource = GetComponent<AudioSource>(); //Initialize the pitch audioSource.pitch = startingPitch; } void Update() { //While the pitch is over 0, decrease it as time passes. if (audioSource.pitch > 0) { audioSource.pitch -= Time.deltaTime * startingPitch / timeToDecrease; } } } ``` 另一个示例: ``` using UnityEngine; // A script that plays your chosen song. The pitch starts at 1.0. // You can increase and decrease the pitch and hear the change // that is made. public class AudioExample : MonoBehaviour { public float pitchValue = 1.0f; public AudioClip mySong; private AudioSource audioSource; private float low = 0.75f; private float high = 1.25f; void Awake() { audioSource = GetComponent<AudioSource>(); audioSource.clip = mySong; audioSource.loop = true; } void OnGUI() { pitchValue = GUI.HorizontalSlider(new Rect(25, 75, 100, 30), pitchValue, low, high); audioSource.pitch = pitchValue; } } ```
da
2022年5月24日 10:01
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码