/// <summary> /// Resumes playing the current music if it's not already playing /// </summary> public void ResumeMusic() { if (m_musicClip.Info == null || m_musicClip.IsPlaying) { return; } m_musicClip.Play(); }
void Start() { if (shootSound != null && shootSound.loop) { shootSound.Play(transform.position, gameObject); } else { shootSound.Play(transform.position); } }
/// <summary> /// Plays the given sound /// Waits until the sound is done playing /// Stops the sound and adds it back to the resource pool /// If the sound is set to loop then it won't add it back to the queue /// until it is done looping /// </summary> /// <param name="soundName"></param> /// <returns></returns> IEnumerator PlaySoundRoutine(AudioName soundName, SoundClip clip) { AudioClipInfo info = m_aduioDictionary[soundName]; clip.Info = info; clip.Volume = m_sfxVolume; clip.Play(); // Will keep checking until the sound no longer plays if (clip.Loops) { // Check again next frame to see if we are done while (clip.IsPlaying) { yield return(new WaitForEndOfFrame()); } } else { // Wait until the sound is done playing to re-queue it yield return(new WaitForSeconds(clip.Length)); } // For safety ensure the sound is stopped clip.Stop(); clip.Info = null; m_soundClips.Enqueue(clip); }
private void HitObject(HitTarget hitTarget, Rigidbody hitRigidbody) { hitSound.Play(transform.position); if (triggerEffectsOnEachHit || hitCount >= hits) { if (hitTarget != null) { foreach (var effect in hitTargetEffects) { effect.Hit(this, hitTarget); hitTarget.HitEffectTaken(this, effect); } hitTarget.HitTaken(this); } if (hitRigidbody != null) { foreach (var effect in hitRigidbodyEffects) { effect.Hit(this, hitRigidbody); } } } }
public void StartGrapple() { if (currentHook == null || Grappling) { return; } Grappling = true; Latched = false; hookRigidbody = currentHook.rigidbody; latchTotalTime = (currentHook.transform.position - ropeEffectSource.position).magnitude / latchSpeed; latchTime = 0; //obstacleTime = 0; reelIn = false; normalizedTilt = Vector3.zero; armHookTransform.SetParent(null, true); ClearRopeEffect(); ropeEffect = Instantiate(ropeEffectPrefab, ropeEffectSource.position, Quaternion.identity, ropeEffectSource); ropeEffect.SetTravelTime(latchTotalTime); if (hookLaunch != null) { hookLaunch.Play(transform.position); } }
public override void Hit() { var projectile = GameObject.Instantiate(projectilePrefab, unit.AttackPoint.position, unit.AttackPoint.rotation); var player = LevelTracker.I.player; if (player != null) { Vector3 shootVector = unit.AttackPoint.forward; shootVector.y = (player.transform.position - unit.AttackPoint.position).normalized.y; projectile.AddForce(shootVector * launchSpeed, ForceMode.VelocityChange); } else { projectile.AddForce(unit.AttackPoint.forward * launchSpeed, ForceMode.VelocityChange); } if (soundClip != null) { soundClip.Play(unit.transform.position); } // var slashEffect = GameObject.Instantiate(slashEffectPrefab, // unit.AttackPoint.position, unit.AttackPoint.rotation); }
/// <summary> /// Sets the master volume for the sound effects /// </summary> /// <param name="volume"></param> public void SetMasterSFXVolume(float volume) { m_sfxVolume = volume; m_testSfxClip.Volume = volume; // Play the sample sfx if (!m_testSfxClip.IsPlaying) { m_testSfxClip.Play(); } }
public override void Enter(Unit unit) { base.Enter(unit); if (soundClip != null) { soundClip.Play(unit.transform.position); } // if (unit.motor != null) // unit.motor.SetTargetRotation(lookDirection, 30); }
private void playSoundClip_Click(object sender, RoutedEventArgs e) { try { SoundClip soundClip = new SoundClip(new Uri(SOUNDCLIP_URL, UriKind.RelativeOrAbsolute)); soundClip.Play(); } catch (Exception ex) { status.Log(ex.Message); } }
public void TakeDamage(int damage, HitTrigger hitTrigger = null) { HP = HP - damage; if (HP <= 0) { Kill(hitTrigger); } else if (hurtSound != null) { hurtSound.Play(transform.position); } }
public bool Jump() { if (Grounded || jumpGraceTimeRemaining > 0) { jumpTimeRemaining = jumpTime; if (jumpSound != null) { jumpSound.Play(transform.position); } return(true); } return(false); }
public override void Enter(Unit unit) { base.Enter(unit); playerMotor = unit.GetComponent <PlayerMotor>(); float velocityChange = Mathf.Max(0, Mathf.Max(unit.rigidbody.velocity.y, jumpVelocity) - unit.rigidbody.velocity.y); // can't use AddForce because we want to read the correct velocity value later this frame unit.rigidbody.velocity = unit.rigidbody.velocity + Vector3.up * velocityChange; if (soundClip != null) { soundClip.Play(unit.transform.position); } }
/// <summary> /// Spawns a new object with an AudioSource to fire off the sound given /// Thus preventing the same sound trying to play twice from the same audio source /// Triggers the destruction of the object based on the clip's length /// </summary> /// <param name="soundName"></param> public void PlaySound(string soundName) { if (this.soundClips.ContainsKey(soundName)) { GameObject soundGO = new GameObject(soundName); soundGO.AddComponent(typeof(SoundClip)); SoundClip soundClip = this.soundClips[soundName]; soundClip.SetSource(soundGO.AddComponent <AudioSource>()); soundClip.Play(); Destroy(soundGO, soundClip.clip.length); } }
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { float fracPart = stateInfo.normalizedTime - (float)System.Math.Truncate(stateInfo.normalizedTime); if (!played1 && fracPart > 0.4f) { played1 = true; sound.Play(animator.transform.position); } else if (played1 && fracPart < 0.4f) { played1 = false; } if (!played2 && fracPart > .9f) { played2 = true; sound.Play(animator.transform.position); } else if (played2 && fracPart < .9f) { played2 = false; } }
public static Node Create() { var clip = new SoundClip ("BattleScene"); clip.AddTrack(new MusicTrack("media/BGM-BattleScene.ogg")); clip.Play (); clip.Volume = 0.5f; var ply = new SoundPlayer (); ply.AddClip (clip); var node = new Node ("BGM"); node.Attach (ply); return node; }
public override void Enter(Unit unit) { base.Enter(unit); Quaternion lookDirection = GameManager.I.BaseCamera.transform.rotation; if (unit.motor != null) { unit.motor.SetTargetRotation(lookDirection, 30); } if (soundClip != null) { soundClip.Play(unit.transform.position); } }
public override void Enter(Unit unit) { base.Enter(unit); lookDirection = GameManager.I.BaseCamera.transform.rotation; if (unit.motor != null) { unit.motor.SetTargetRotation(lookDirection, 30); } dashSpeed = Mathf.Max(dashSpeed, unit.rigidbody.velocity.magnitude / 2 + dashSpeed); if (soundClip != null) { soundClip.Play(unit.transform.position); } }
public void Kill(HitTrigger hitTrigger = null) { if (deathSound != null) { deathSound.Play(transform.position); } if (sliceable != null) { sliceable.SliceAndDestroy(hitTrigger); } else { Destroy(gameObject); } }
IEnumerator FadeIn(SoundClip clip) { float time = FadeInTime; float origVolume = clip.standardVolume; while (time > 0) { time -= Time.deltaTime; clip.volume = Mathf.Lerp(origVolume, 0, time / FadeInTime); yield return(null); } clip.volume = origVolume; clip.Play(); }
public static World Create() { var cmp = new MyWorld (); var spr = new Sprite (new Texture ("media/DarkGalaxy.jpg")); var clip = new SoundClip (); clip.AddTrack (new MusicTrack ("media/BGM(Field04).ogg")); clip.Play (); clip.Volume = 0.3f; var wld = new World ("First Script"); wld.Attach (cmp); wld.Attach (spr); wld.UserData.Add (clip.Name, clip); wld.DrawPriority = 127; return wld; }
public override void Hit(HitTrigger trigger, HitTarget target) { var scrapComponent = trigger.GetComponent <CollectableScrap>(); if (scrapComponent == null) { trigger.Destroy(); } var playerMotor = target.GetComponent <PlayerMotor>(); if (playerMotor != null) { playerMotor.scrap.Value += scrap; playerMotor.AddSteam(1); if (pickupSound != null) { pickupSound.Play(target.transform.position); } trigger.Destroy(); } }
private void UpdateGroundPhysics() { RaycastHit hitInfo; if (jumpTimeRemaining > 0) { Grounded = false; } else { Vector3 colliderBottom = new Vector3(collider.bounds.center.x, collider.bounds.min.y, collider.bounds.center.z); bool wasGrounded = Grounded; //if (!Grounded) Grounded = Physics.Raycast( colliderBottom + 0.1f * Vector3.up, (groundSensorLength + 0.1f) * Vector3.down, out hitInfo, 0.3f, LayerManager.I.WalkableMask, QueryTriggerInteraction.Ignore); if (Grounded) { //unit.rigidbody.MovePosition(hitInfo.point - (colliderBottom - unit.rigidbody.position)); unit.rigidbody.AddForce(Mathf.Max(0, unit.rigidbody.velocity.y) * Vector3.down, ForceMode.VelocityChange); jumpGraceTimeRemaining = jumpGraceTime; if (!wasGrounded && landSound != null) { var sound = landSound.Play(transform.position); } } } if (!Grounded) { unit.rigidbody.AddForce(gravity * Vector3.down, ForceMode.Acceleration); jumpGraceTimeRemaining -= Time.fixedDeltaTime; } }
/// <summary> /// 即刻播放声音 /// </summary> /// <param name="name"></param> public SoundClip playSound(string name, bool isFroce = false, bool isUI = false) { if (string.IsNullOrEmpty(name)) { return(null); } SoundClip soundClip = null; if (_soundsDictionary.TryGetValue(name, out soundClip)) { soundClip.soundValue = soundValue; if (soundClip.isPlaying == false) { soundClip.Play(); } else if (isFroce) { soundClip.time = 0f; } return(soundClip); } soundClip = getSoundInstance(); _soundsDictionary.Add(name, soundClip); soundClip.soundValue = soundValue; soundClip.name = name; soundClip.addEventListener(EventX.COMPLETE, completeHandle); string url = getURL(name, isUI); soundClip.load(url); return(soundClip); }
void FixedUpdate() { if (!Grappling || currentHook == null) { ClearRopeEffect(); return; } Vector3 hookVector = currentHook.transform.position - ropeEffectSource.position; // obstacles break rope - don't think this mechanic is fun // if (Physics.Raycast(ropeEffectSource.position, hookVector, // hookVector.magnitude, LayerManager.I.GroundMask)) { // obstacleTime += Time.fixedDeltaTime; // if (obstacleTime > obstacleGraceTime) { // StopGrapple(); // return; // } // } if (!Latched) { latchTime += Time.fixedDeltaTime; if (latchTime >= latchTotalTime) { Latched = true; latchStartSpeed = sourceRigidbody.velocity.magnitude; if (hookLatch != null) { hookLatch.Play(transform.position); } } } else { if (hookRigidbody == null) // attached to a static hook object { float dp = Vector3.Dot(sourceRigidbody.velocity, hookVector); if (dp < 0) // if the vectors are facing different directions, limit the velocity moving away from the rope { Vector3 rejection = sourceRigidbody.velocity - (dp / Vector3.Dot(hookVector, hookVector)) * hookVector; Vector3 targetVelocity = 1.005f * sourceRigidbody.velocity.magnitude * rejection.normalized; targetVelocity = Mathf.Min(Mathf.Max(swingMaxSpeed, latchStartSpeed), targetVelocity.magnitude) * targetVelocity.normalized; Vector3 velocityChange = targetVelocity - sourceRigidbody.velocity; sourceRigidbody.AddForce(velocityChange, ForceMode.VelocityChange); } if (reelIn) { Vector3 aboveHook = currentHook.transform.position + 1 * currentHook.transform.up; Vector3 pullVector = aboveHook - ropeEffectSource.position; Vector3 velocityChange = (Mathf.Max(reelSpeed, sourceRigidbody.velocity.magnitude) * pullVector.normalized) - sourceRigidbody.velocity; velocityChange.y = Mathf.Max(0, velocityChange.y); velocityChange = Mathf.Min(reelAccel, velocityChange.magnitude) * velocityChange.normalized; sourceRigidbody.AddForce(velocityChange, ForceMode.VelocityChange); } if ((ropeEffectSource.position - currentHook.transform.position).sqrMagnitude < 2 * 2) { StopGrapple(); } } else // attached to a dynamic hook object { } } }
//Play with loop, must stop manually public static bool PlaySoundEffectOneShot(string name, bool loop, float volume) { //Don't do shit if mute if (GlobalMuteSFX) return false; //Check total count, play nothing if > max if (m_Instance.m_ActiveSound >= MAX_ACTIVE_SFX) return false; //Check first if looping, don't create again if already there if (loop) { foreach(SoundClip clip in m_Instance.m_SoundEffectOneShot) { if (clip.Name == name) { //Play again clip.Play(); //Return here return true; } } } //Create new sound clip SoundClip s = new SoundClip(name, SFX_PATH); s.Volume = volume; s.Loop = loop; //Add to list and play m_Instance.m_SoundEffectOneShot.Add(s); s.Play(); //Add number m_Instance.m_ActiveSound++; return true; }