AUDIO SCRIPTS - Форум
  • Страница 1 из 1
  • 1
Модератор форума: terex  
AUDIO SCRIPTS
terexДата: Воскресенье, 13.03.2011, 01:11 | Сообщение # 1
Zzz
Группа: Администраторы
Сообщений: 71
Награды: 1
Репутация: 32767
Статус: Offline
скрипт playlist
позволяет поставить нужное количество треков и их проиграть

Code
// Воспроизведение одним из аудио выбирая случайным между ними
var clips : AudioClip[] = new AudioClip[1];

function Start ()
{
     DontDestroyOnLoad(this);
     audio.loop = false;
     while (true)
     {
        audio.clip = clips[Random.Range(0, clips.length)];
        audio.Play();     
        if (audio.clip)
           yield WaitForSeconds(audio.clip.length);
        else
           yield;
     }
}

@script RequireComponent(AudioSource)
 
terexДата: Воскресенье, 13.03.2011, 02:16 | Сообщение # 2
Zzz
Группа: Администраторы
Сообщений: 71
Награды: 1
Репутация: 32767
Статус: Offline
скрипт pauseSound повторяет audio трек по кругу

Code
#pragma strict

class PauseSound extends MonoBehaviour
{
      private var _paused : boolean;
      private var _audioSources : AudioSource[];
      public var ZeroVolume : boolean = false;

      private var _currentVolume : float[];

      function Start()
      {
          _paused = false;

          var c : Component[] = gameObject.GetComponents(AudioSource) as Component[];
            
          if(c == null || c.Length <= 0)
          {
              if(audio != null)
              {
                  _audioSources = new AudioSource[1];
                  _currentVolume = new float[1];
                  _audioSources[0] = audio;
              }
              else
              {
                  Destroy(this);
              }
          }
          else
          {
              _audioSources = new AudioSource[c.Length];
              _currentVolume = new float[c.Length];

              for(var i : int = 0; i < c.Length; i++)
              {
                  if(c[i] == null) continue;

                  _audioSources[i] = c[i] as AudioSource;      
                  _currentVolume[i] = _audioSources[i].volume;
              }
          }
      }

      function Update()
      {
          var i : int;

          if(GameManager.pause)
          {
              if(!_paused)
              {
                  _paused = true;

                  for(i = 0; i < _audioSources.Length; i++)
                  {
                      if(_audioSources[i] == null) continue;

                      if(!ZeroVolume)
                      {
                          _audioSources[i].Pause();
                      }
                      else
                      {
                          _audioSources[i].volume = 0.0;
                      }
                  }
              }
          }
          else
          {
              if(_paused)
              {  
                  _paused = false;

                  for(i = 0; i < _audioSources.Length; i++)
                  {
                      if(_audioSources[i] == null) continue;

                      if(!ZeroVolume)
                      {
                          _audioSources[i].Play();
                      }
                      else
                      {
                          _audioSources[i].volume = _currentVolume[i];
                      }
                  }
              }
          }
      }   
}
 
terexДата: Суббота, 26.03.2011, 04:09 | Сообщение # 3
Zzz
Группа: Администраторы
Сообщений: 71
Награды: 1
Репутация: 32767
Статус: Offline
при наведении мышкой на объект, проигрывается audio track
Code
var wood_impact_weak :AudioClip;

function OnMouseEnter()

{

audio.PlayOneShot(wood_impact_weak);

}

function Start()

{

gameObject.AddComponent("AudioSource");

audio.playOnAwake = false;

audio.loop = false;

}
 
  • Страница 1 из 1
  • 1
Поиск:
 Сайт временно находится в стадии разработки, приношу свои извинения за не удобства
 
 This site is temporarily under construction, I apologize for the convenience of not