本文整理汇总了C#中UnityEngine.AudioClip类的典型用法代码示例。如果您正苦于以下问题:C# AudioClip类的具体用法?C# AudioClip怎么用?C# AudioClip使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AudioClip类属于UnityEngine命名空间,在下文中一共展示了AudioClip类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PlayMusic
public void PlayMusic(AudioClip clip, float fadeDuration = 1) {
activeMusicSourceIndex = 1 - activeMusicSourceIndex;
musicSources[activeMusicSourceIndex].clip = clip;
musicSources[activeMusicSourceIndex].Play();
StartCoroutine(AnimateMusicCrossfade(fadeDuration));
}
示例2: PlayMusic
/**
* Plays game music using an audio clip.
* One music clip may be played at a time.
* @param musicClip The music clip to play
* @param atTime Time in the music clip to start at
*/
public void PlayMusic(AudioClip musicClip, bool loop, float fadeDuration, float atTime)
{
AudioSource audioSource = GetComponent<AudioSource>();
if (audioSource == null || audioSource.clip == musicClip)
{
return;
}
if (fadeDuration == 0f)
{
audioSource.clip = musicClip;
audioSource.loop = loop;
audioSource.time = atTime; // May be inaccurate if the audio source is compressed http://docs.unity3d.com/ScriptReference/AudioSource-time.html BK
audioSource.Play();
}
else
{
float startVolume = audioSource.volume;
LeanTween.value(gameObject, startVolume, 0f, fadeDuration)
.setOnUpdate( (v) => {
// Fade out current music
audioSource.volume = v;
}).setOnComplete( () => {
// Play new music
audioSource.volume = startVolume;
audioSource.clip = musicClip;
audioSource.loop = loop;
audioSource.time = atTime; // May be inaccurate if the audio source is compressed http://docs.unity3d.com/ScriptReference/AudioSource-time.html BK
audioSource.Play();
});
}
}
示例3: ParseTextAndSpeak
//This is called by the Line Reader to parse a string and begin speaking
public void ParseTextAndSpeak(string inputText, AudioClip inputAudio)
{
mouthQueue.Clear();
textTime.Clear();
currentSyllable = 0;
//split the string up into
string[] splitString = inputText.Split(';');
for (int i = 0; i < splitString.Length; i++)
{
for (int m = 0; m < mouths.Length; m++)
{
for (int s = 0; s < mouths[m].syllable.Length; s++)
{
if (splitString[i].StartsWith(mouths[m].syllable[s]))
{
mouthQueue.Add(m);
textTime.Add(splitString[i].Length * timePerInputCharacter);
//break;
}
}
}
}
//reset the coroutine
CancelInvoke("SetNextMouth");
SetNextMouth();
myAudio.clip = inputAudio;
myAudio.Play();
}
示例4: OnShoot
void OnShoot()
{
gunshot = Resources.Load<AudioClip>("Sounds/gunfire");
source = GetComponent<AudioSource>();
source.PlayOneShot(gunshot);
}
示例5: PlayOneShot
void PlayOneShot(AudioClip sound)
{
if(_state == State.Play)
{
SoundPlayer.PlayOneShot(sound);
}
}
示例6: playSoundRandom
public void playSoundRandom(Vector3 soundPos, AudioClip []arrayOfSounds, int sizeOfArray, int []availableSounds, int lenghtOfAvailableSounds)
{
bool numIsUsable = false;
int ranNum = 0;
for (int a = 0; a < 20; a++)
{
ranNum = Mathf.RoundToInt(Random.Range(0, sizeOfArray));
for (int b = 0; b < lenghtOfAvailableSounds; b++)
{
if (ranNum == availableSounds[b])
{
numIsUsable = true;
break;
}
}
if (numIsUsable)
break;
}
if (numIsUsable)
{
source.PlayOneShot(arrayOfSounds[ranNum]);
//AudioSource.PlayClipAtPoint(arrayOfSounds[ranNum], soundPos);
Debug.Log(ranNum);
}
}
示例7: Start
void Start()
{
_audioSource = gameObject.AddComponent <AudioSource>();
_godzillaDamageAudioclip = _doLoadAudioClipByName (MainConstants.AUDIO_GODZILLA_DAMAGE);
_mazingerDamageudioclip = _doLoadAudioClipByName (MainConstants.AUDIO_MAZINGER_DAMAGE);
}
示例8: Play
public void Play(AudioClip sound)
{
GameObject temp;
if (soundObjects.TryGetValue(sound, out temp)) {
if (!temp.GetComponent<AudioSource>().isPlaying) temp.GetComponent<AudioSource>().Play();
}
}
示例9: Stop
public void Stop(AudioClip sound)
{
GameObject temp;
if (soundObjects.TryGetValue(sound, out temp)) {
temp.GetComponent<AudioSource>().Stop ();
}
}
示例10: ReplaceMusic
public void ReplaceMusic(AudioClip muse, float newVolume)
{
if (ownSource.clip != muse){
nextMusic = muse;
maxVolume = newVolume;
}
}
示例11: justplaySfx
IEnumerator justplaySfx(AudioClip _clip,float volume)
{
//audio.PlayOneShot (_clip, volume);
audio.PlayOneShot (_clip, volume);
yield return null;
}
示例12: PlaySoundLoop
public void PlaySoundLoop(AudioClip inClip, float timeDelay = 0)
{
audio.loop = true;
audio.clip = inClip;
//audio.Play();
audio.PlayDelayed(timeDelay);
}
示例13: PlaySoundAt
public AudioSource PlaySoundAt(AudioClip clip, Transform soundParent, string tag = "Untagged")
{
AudioSource source = PlaySoundAt(clip, soundParent.position, tag);
source.transform.SetParent(soundParent, false);
source.transform.localPosition = new Vector3(0, 0, 0);
return source;
}
示例14: setCard
//Method that other scripts can use to pass new sprites into this object
public void setCard(Sprite image, int inputId, string t, AudioClip c)
{
clip = c;
id = inputId;
type = t;
GetComponent<SpriteRenderer>().sprite = image;
}
示例15: Play
public void Play(AudioClip clip, float volume = 1.0f)
{
if (clip != null)
{
_source.PlayOneShot(clip, _source.volume * volume);
}
}