void CreateSoundObject() { SoundObj soundObj = GameObject.Instantiate(SoundObjPrefab).GetComponent <SoundObj>(); soundObj.controller = this; SoundObjects.AddLast(soundObj); }
void Explode() { GameObject newSound = Instantiate(soundPrefab, hit.transform.position, hit.transform.rotation); if (smallExplosion != null) { SoundObj so = newSound.GetComponent <SoundObj>(); if (so != null) { so.GotHit(); } } else { Debug.Log("smallExplosion is null as"); } GameObject explode = (GameObject)Instantiate(hitEffect, transform.position, transform.rotation); Collider[] colliders = Physics.OverlapSphere(transform.position, radius); foreach (Collider nearbyObject in colliders) { Rigidbody rigi = nearbyObject.GetComponent <Rigidbody>(); if (rigi != null) { if (rigi.gameObject.tag == "Player" && rigi.gameObject.name != objectToIgnore) { PlayerDamage pd = rigi.gameObject.GetComponent <PlayerDamage>(); pd.TakeDamage(1f, toScore); } } } Destroy(explode, 0.5f); }
public void Update() { for (int idx = 0; idx < _soundList.Count; ++idx) { SoundObj obj = _soundList[idx]; if (obj.IsUsing) { obj.Update(Time.deltaTime); } } }
private static void PlayClipAt(AudioClip clip, bool setPos = false, Vector3 pos = new Vector3()) { var tempGO = new SoundObj("TempAudio - " + clip.name, instance?.parrentTransform); if (setPos) { tempGO.gameObject.transform.position = pos; } tempGO.aSource.PlayOneShot(clip); Destroy(tempGO.gameObject, clip.length); }
//------------------------------------------------------------------------------// #endregion #region Recording functions //------------------------------------------------------------------------------// public void RecordInitialize(SoundObj soundObj) { state = State.recordInit; curRecSoundObj = soundObj; //if first recording, use metronome //with pickup, stop first everything GlobalTime.Instance.Stop(); GlobalTime.Instance.Record(); }
private void StopSound() { GameObject actor = GameObject.Find(Actor); AudioSource[] aSources = actor.GetComponents <AudioSource>(); SoundObj sound = ObjectController.Get().GetObject <SoundObj>(ObjectCategories.Sound, Name); for (int i = 0; i < aSources.Length; ++i) { if (aSources[i].clip.name == sound.Sound.name) { aSources[i].Stop(); } } }
public GameObject PlaySound(string path) { GameObject soundObj = new GameObject(); soundObj.transform.parent = _Instance.gameObject.transform; soundObj.transform.localPosition = Vector3.zero; soundObj.name = "SoundObj"; AudioSource audioSource = soundObj.AddComponent <AudioSource>(); audioSource.clip = Resources.Load <AudioClip>(path); audioSource.volume = PlayerPrefs.GetFloat("OtherSoundVolume", 1); SoundObj soundCtr = soundObj.AddComponent <SoundObj>(); soundCtr.AudioSource = audioSource; return(soundObj); }
IEnumerator WaitUntilFinishedStoringAudio() { curRecSoundObj.RecordFinish(); Debug.Log("audio being stored"); while (curRecSoundObj.state != SoundObj.State.audioSecured) { yield return(null); } Debug.Log("done storing audio"); curRecSoundObj = null; GlobalTime.Instance.Play(); state = State.ready; }
private SoundObj _getSoundObj() { SoundObj obj = null; for (int idx = 0; idx < _soundList.Count; ++idx) { if (!_soundList[idx].IsUsing) { obj = _soundList[idx]; break; } } if (obj == null) { obj = new SoundObj(); _soundList.Add(obj); } return(obj); }
private void PlaySound() { SoundObj sound = ObjectController.Get().GetObject <SoundObj>(ObjectCategories.Sound, Name); GameObject actor = GameObject.Find(Actor); if (sound == null) { Debug.LogError("Cannot find sound: " + Name); //Debug.Break(); } if (actor == null) { Debug.LogError("Cannot find actor: " + Actor); //Debug.Break(); } try { Debug.Log("Within PlaySound try block"); AudioSource aSource; if (actor.audio && !actor.audio.isPlaying) { aSource = actor.audio; } else { aSource = actor.AddComponent <AudioSource>(); } aSource.loop = Loop; aSource.clip = sound.Sound; aSource.Play(); } catch { } // We already know what this could be, we don't care, dev will get the warning in console already. }
public GameObject PlayBackground(string path) { GameObject soundObj = GameObject.Find("BackgroundSoundObj"); if (soundObj != null) { return(soundObj); } soundObj = new GameObject(); soundObj.transform.parent = _Instance.gameObject.transform; soundObj.transform.localPosition = Vector3.zero; soundObj.name = "BackgroundSoundObj"; DontDestroyOnLoad(soundObj); AudioSource audioSource = soundObj.AddComponent <AudioSource>(); audioSource.clip = Resources.Load <AudioClip>(path); audioSource.volume = PlayerPrefs.GetFloat("BGSoundVolume", 1); audioSource.loop = true; SoundObj soundCtr = soundObj.AddComponent <SoundObj>(); soundCtr.IsLoop = true; soundCtr.AudioSource = audioSource; return(soundObj); }
public void AddSound(SoundObj sound) { Debug.Log("Adding: " + sound.Name); Sounds.Add(sound); }