- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在为一项任务搞乱 Unity,我创建了一个“伤害链”,如果我造成伤害的速度足够快,伤害链就会增加。
然后,当伤害链足够高时,我想从背景音乐切换到 Metallica 的“Enter Sandman”...
但是当我将“Enter Sandman”MP3 添加到层次结构中的背景音乐对象时,我必须添加第二个具有相同名称(即音频源)的“音频源”。
然后,当我尝试在代码中管理它时,我不能只运行 GetComponent<AudioClip>
就像我在其他任何地方一样。
如何在脚本中的两首歌曲之间切换?这是我的对象设置的图片,然后是代码...
还有,我的代码(原样),SongManager:
using UnityEngine;
using System.Collections;
public class SongManager : MonoBehaviour {
AudioSource regular_music;
AudioSource high_dmg_music;
// Use this for initialization
void Start () {
regular_music = GetComponent<AudioSource> ();
high_dmg_music = GetComponent<AudioSource> ();
regular_music.loop = true;
regular_music.Play ();
high_dmg_music.loop = false;
high_dmg_music.Stop ();
}
// Update is called once per frame
void Update () {
if (DamageManager.dmg_chain > 1500) {
regular_music.loop = false;
high_dmg_music.loop = true;
high_dmg_music.Play ();
} else {
if (high_dmg_music.isPlaying) {
high_dmg_music.loop = false;
high_dmg_music.Stop ();
regular_music.loop = true;
regular_music.Play ();
}
}
}
}
很明显,代码不行,但我还是写完了。
我将如何实现此配置?
最佳答案
只创建一个AudioSource
。创建许多 AudioClips
,然后将要播放的每个 AudioClip
重新分配给 AudioSource
。将声音拖到 AudioClip
插槽中。
public AudioClip background_music;
public AudioClip sandman_music;
private AudioSource audioSource;
Void Start()
{
audioSource = GetComponent<AudioSource>();
//To play backround sound
if (audioSource.isPlaying)
{
audioSource.Stop();
}
audioSource.clip = background_music;
audioSource.Play();
//To play sandman sound
if (audioSource.isPlaying)
{
audioSource.Stop();
}
audioSource.clip = sandman_music;
audioSource.Play();
}
关于c# - 统一: Survival Shooter Tutorial: How to switch between two background songs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37378553/
我不知道如何执行以下查询。我有 3 张 table : song (song_id, title, is_draft) author (author_id, name) song_author (so
我使用 libsndfile 来加载音乐文件,并使用 jack 来播放它。 当歌曲的采样率低于或高于声卡的采样率时,如何解决问题?我可以在 jack 中配置一些东西,还是需要使用 libsampler
我收到此错误,不确定为什么我的程序基本上是读取.txt文件并将其保存到数组吗?任何帮助深表感谢。 error message:Exception in thread "main" java.lang.
我正在尝试构建一个播放Spotify歌曲的应用程序。我真的很困惑如何更改Spotify歌曲的BPM(每分钟节拍数)值。 第一步:通过Spotify登录。 第二步:获取当前用户的所有相册。 第三步:获取
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
在我问我的问题之前,我只是想说我对 Javascript 和 StackOverflow 一般都是菜鸟,所以如果这个问题太愚蠢,我想提前道歉。 无论如何,我正在学习 Javascript,现在我正在试
我一直在尝试在我当前的应用程序中包含 Song.FromURI() 方法,但总是出现“CrossThreadMessagingException”。 我已经开始了一个新项目,并从字面上复制并粘贴了 M
我正在玩我的手机,上面有这个应用程序,当你用它录制一首歌的 10 秒时,它会告诉你那首歌的标题和作者。现在作为一名软件工程师,我不禁想知道,这是如何工作的? 最佳答案 嗯,实际上Shazam 写了一篇
我无法更新需要从ongsList获取值的状态歌曲。如何将歌曲更新到songsList ?这与组件的生命周期有什么关系吗?运行以下代码时,会出现“songsList is undefined”错误。 c
我正在开发一个与音乐相关的安卓应用程序。如果能够看到哪些歌曲(如果有的话)是用户在他们的 Android 设备上播放最多的歌曲,那将是一个很好的功能。或者他们主演或制作最喜欢列表的歌曲。这可能吗?这些
我试图让这首歌在歌曲结束时重播,但它似乎不起作用。这就是我实现它的方式: var music1 : AVAudioPlayer! = AVAudioPlayer() func setUpMusic()
我想知道当给定歌曲有多个艺术家时,最好的建模方法是什么。 id song_title artist ======================================
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 4 年前。 Improve this ques
试图通过这个编程 ruby 站点获取 ruby,但我被这个语法困住了 class SongList def initialize @songs = Array.new end
正如 Apple 在 iOS 9.3 中所说,我们可以 Access Apple Music Library .我正在通过 MPMusicPlayerController 从我的应用程序中播放它。 我
我知道如何检索特定歌曲的流派(请参阅 getting the genres ),但我想检索特定流派的所有歌曲。由于“流派”似乎不是媒体项目的列之一,所以我不知道如何在单个查询中做到这一点,这与艺术家或
我正在尝试弄清楚如何使用 Google Music API。我设法获得了在 http://dpogue.ca/gmusic.html 中描述的身份验证 token : $ curl -d accoun
type Song = (String, String, Int) --(title, artist, sales) database :: [Song] database = [("Amon Ama
我正在使用API从天才那里获取歌曲歌词。保存后,我从JSON文件中提取标题和歌词时遇到问题。请在下面查看我的代码。 import lyricsgenius as genius api=genius
type Song = (String, String, Int) --(title, artist, sales) database :: [Song] database = [("Amon Ama
我是一名优秀的程序员,十分优秀!