English 中文(简体)
统一能够给实地监察员带来实情
原标题:Unity can t put sound to inspector field

I have sound source and my question is how can I play that sound when my cube hit a wall? My code:

usingUnityEngine;
usingSystem.Collections;

public class sound : MonoBehaviour {

public AudioSource soundEffect;

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

我可以把视听来源分派给检查员。 我可以把我的<代码>*>。

怎么办?

成就

问题回答

如果你向河中添加一个声音源,并将档案存放在资源中,那么,只要你想要播放音响的话,你就可以这样做。

GetComponent<AudioSource>().clip = Resources.Load<AudioClip>("audioFile");
GetComponent<AudioSource> ().Play ();

C#

为我工作的一些论文:

-Add the Audio File as a component on the cube -Then simply drag that file from INSPECTOR to the public AudioSource Field.





相关问题
Playing a Sound With Monotouch

No matter what I try (build -> content, NSUrl, filename) I get a null exception : file not found when I try to play a .caf sound file in monotouch. //var path = NSBundle.MainBundle.PathForResource("...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

Play sound in iPhone web app with Javascript?

I m currently creating an iPhone web application for piano chords, and I wanted to add an option that would let the user press a Play button and play the selected chord. However, I m not sure how to ...

热门标签