相同的GameObject两个音频源未播放其音频片段-Unity

时间:2018-11-14 09:32:56

标签: unity3d audio-source

我当时正在从事3d跑步类游戏的开发,因此我在Player GameObject中附加了两个AudioSources组件:

  1. 用于播放游戏音乐的AudioSource
  2. 播放播放器碰撞声的AudioSource

在同一Player GameObject上,我已分配了两个AudioSources来播放这两种声音,但目前仅在播放GamePlay音乐,当碰撞障碍物时不会播放Player碰撞声。

enter image description here

两个AudioSource都有分配的AudioClip。

在有障碍物的碰撞时间,我正在像这样播放碰撞声:

    func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {

        switch (type) {
        case .insert:
            if indexPath != nil && (indexPath?.row)! < (controller.fetchedObjects?.count)!{
                tableView.insertRows(at: [indexPath!], with: .left)
            }
            break;

        case .update:
            if indexPath != nil && (indexPath?.row)! < (controller.fetchedObjects?.count)!{
                self.tableView.reloadRows(at: [indexPath!], with: .left)
            }
            break;

        case .delete:
            if indexPath != nil && (indexPath?.row)! < (controller.fetchedObjects?.count)!{
                self.tableView.deleteRows(at: [indexPath!], with: .left)
            }
            break;

        case .move:
            if indexPath != nil && (indexPath?.row)! < (controller.fetchedObjects?.count)!{
                print("type.move: shouldn't get in here!")
            }
            break;

        }
    }

GamePlay音乐正常播放,当它与障碍物碰撞但播放器碰撞声音未播放时会停止播放。

1 个答案:

答案 0 :(得分:2)

好的,我设法自己解决了这个问题。如果GameObject被禁用,则其AudioSources将无法播放。

在上面的 .fb_iframe_widget span, iframe.fb_iframe_widget_lift, .fb_iframe_widget iframe { width: 500px !important; height: 500px !important; } 方法中,我禁用了Player GameObject,因此AudioSource不会产生任何声音。