UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
AudioSource.loop
# [AudioSource](https://docs.unity3d.com/cn/2019.4/ScriptReference/AudioSource.html).loop public bool **loop** ; ## 描述 是否循环播放该音频剪辑? 返回或设置在完成某音频剪辑的播放后是否重放该音频剪辑。 如果对正在播放的 AudioSource 禁用循环播放,则在当前循环结束后停止播放该声音。AudioSource 组件中有一个复选框,让您能够在不编写代码的情况下启用或禁用循环播放。 ``` //Create an empty GameObject and attach this script //Attach an AudioSource component. (Click on the GameObject, go to its Inspector and click Add Component Button. Go to Audio>Audio Source) //Attach an Audio clip in the AudioClip field of the AudioSource //Create a Button (Create>UI>Button) and a Toggle (Create>UI>Toggle). Attach these in the Inspector of your GameObject. //This script allows you to toggle the loop of a sound on or off using UnityEngine; using UnityEngine.UI; public class AudioSourceLoop : MonoBehaviour { AudioSource m_AudioSource; public Toggle m_Toggle; public Button m_Button; void Start() { //Fetch the AudioSource component of the GameObject (make sure there is one in the Inspector) m_AudioSource = GetComponent<AudioSource>(); //Stop the Audio playing m_AudioSource.Stop(); //Call the PlayButton function when you click this Button m_Button.onClick.AddListener(PlayButton); } void Update() { //Turn the loop on and off depending on the Toggle status m_AudioSource.loop = m_Toggle.isOn; } //This plays the Audio clip when you press the Button void PlayButton() { m_AudioSource.Play(); } } ```
da
2022年5月24日 10:00
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码