【问题标题】:Unity sound when cube hit wall立方体撞墙时的统一声音
【发布时间】:2015-12-07 01:57:49
【问题描述】:

我有声源,我的问题是当我的立方体撞墙时如何播放该声音?

我尝试了类似的方法,但它不起作用。

usingUnityEngine;
usingSystem.Collections;

public class sound : MonoBehaviour {

voidOnTriggerEnter (Colliderother) 
{
if(other.gameObject.tag == "wall")
{

Audio.PlayOneShot(sound);

}

}
}

我希望有人能回答我。对我来说太重要了。这几天我在网上搜索了整个游戏,我对我的游戏做了很多改变,但没有任何效果:(

亲切的问候

【问题讨论】:

  • 初步问题:您的声音文件的格式是什么?你有没有用Debug.Log来检查这个函数是否真的被调用了?
  • Numid 是正确的。使用debug.Log 也可以检查other.gameObject.tag == "wall" 是否为真。

标签: audio unity3d


【解决方案1】:
usingUnityEngine;
usingSystem.Collections;

public class sound : MonoBehaviour {

public AudioSource soundEffect;

voidOnTriggerEnter (Collider other) 
{
   if(other.gameObject.tag == "wall")
   {
      soundEffect.Play ();
   }
}
}

将音频源分配给检查器中的脚本并将脚本分配给立方体。

【讨论】:

  • 代码没问题,但我无法将我的 .mp3 声音添加到脚本中。
  • 你能解释一下发生了什么问题吗?
  • 我无法将文件放在盒子上(“音效:无(​​音频源)”)。我尝试将我的 .mp3 声音放在这条线上,但它不接受。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多