diff options
-rw-r--r-- | Assets/Scenes/Jungle.unity | 26 | ||||
-rw-r--r-- | Assets/Scripts/Actors/Actor.cs | 4 | ||||
-rw-r--r-- | Assets/Scripts/Actors/Player.cs | 4 | ||||
-rw-r--r-- | Assets/Scripts/AudioManager.cs | 24 |
4 files changed, 34 insertions, 24 deletions
diff --git a/Assets/Scenes/Jungle.unity b/Assets/Scenes/Jungle.unity index cdc91a9..f65b9b6 100644 --- a/Assets/Scenes/Jungle.unity +++ b/Assets/Scenes/Jungle.unity @@ -12317,29 +12317,29 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: sounds: + - name: BackgroundMusic + clip: {fileID: 8300000, guid: d2a59924c7fb9004c855636a01875783, type: 3} + volume: 0.25 + pitch: 1 + loop: 1 + source: {fileID: 0} - name: Gunshot clip: {fileID: 8300000, guid: 791560ab56116084ebc209f37a62c59a, type: 3} - volume: 0.5 + volume: 0.6 pitch: 1 loop: 0 source: {fileID: 0} - - name: WhipSwoosh - clip: {fileID: 8300000, guid: dc54d70b8657da04697bfab2772557ee, type: 3} - volume: 0.35 - pitch: 0.85 - loop: 0 - source: {fileID: 0} - name: RunningOnGrass clip: {fileID: 8300000, guid: 6528dc0afee26344d8c5e8e048251645, type: 3} - volume: 1 + volume: 3 pitch: 1 - loop: 0 + loop: 1 source: {fileID: 0} - - name: BackgroundMusic - clip: {fileID: 8300000, guid: d2a59924c7fb9004c855636a01875783, type: 3} + - name: WhipSwoosh + clip: {fileID: 8300000, guid: dc54d70b8657da04697bfab2772557ee, type: 3} volume: 0.3 - pitch: 1 - loop: 1 + pitch: 0.85 + loop: 0 source: {fileID: 0} --- !u!4 &970237753 Transform: diff --git a/Assets/Scripts/Actors/Actor.cs b/Assets/Scripts/Actors/Actor.cs index e7f1a83..eb8185e 100644 --- a/Assets/Scripts/Actors/Actor.cs +++ b/Assets/Scripts/Actors/Actor.cs @@ -21,9 +21,11 @@ namespace MontanaJohns.Actors protected SpriteRenderer _renderer; protected Animator _animator; protected Transform _transform; + protected AudioManager _audio; protected Active activeItem; protected bool isGrappling; + protected bool isMoving; protected Vector2? grapplePoint = null; protected LayerMask groundLayers; protected Collection<Item> items; @@ -42,6 +44,7 @@ namespace MontanaJohns.Actors _transform = GetComponent<Transform>(); _renderer = GetComponent<SpriteRenderer>(); _animator = GetComponent<Animator>(); + _audio = FindObjectOfType<AudioManager>(); groundLayers = LayerMask.GetMask("Grapple", "Ground"); _rigidBody.freezeRotation = true; @@ -73,6 +76,7 @@ namespace MontanaJohns.Actors var target = new Vector2(input * stats.speedMultiplier * 10, _rigidBody.velocity.y); _rigidBody.velocity = Vector2.SmoothDamp(_rigidBody.velocity, target, ref acceleration, .05f); _animator.SetBool("moving", Mathf.Abs(_rigidBody.velocity.x) > 1); + isMoving = Mathf.Abs(_rigidBody.velocity.x) > 1; if (_rigidBody.velocity.x < -0.1) { _renderer.flipX = true; diff --git a/Assets/Scripts/Actors/Player.cs b/Assets/Scripts/Actors/Player.cs index 0483be5..8535a41 100644 --- a/Assets/Scripts/Actors/Player.cs +++ b/Assets/Scripts/Actors/Player.cs @@ -55,6 +55,8 @@ namespace MontanaJohns.Actors else { base.Move(move.ReadValue<Vector2>().x); + if (isMoving && !_animator.GetBool("airborn") && !_audio.isPlaying("RunningOnGrass")) _audio.Play("RunningOnGrass"); + else if (!isMoving || _animator.GetBool("airborn")) _audio.Stop("RunningOnGrass"); } DeathCheck(); } @@ -78,7 +80,7 @@ namespace MontanaJohns.Actors protected void Fire() { Instantiate(projectilePrefab, firePoint.position, firePoint.rotation); - FindObjectOfType<AudioManager>().Play("Gunshot"); + _audio.Play("Gunshot"); } } }
\ No newline at end of file diff --git a/Assets/Scripts/AudioManager.cs b/Assets/Scripts/AudioManager.cs index 1809375..ccb8ebc 100644 --- a/Assets/Scripts/AudioManager.cs +++ b/Assets/Scripts/AudioManager.cs @@ -6,18 +6,8 @@ public class AudioManager : MonoBehaviour { public Sound[] sounds; - public static AudioManager instance; - private void Awake() { - if (instance == null) instance = this; - else { - Destroy(gameObject); - return; - } - - DontDestroyOnLoad(gameObject); - foreach (Sound s in sounds) { s.source = gameObject.AddComponent<AudioSource>(); s.source.clip = s.clip; @@ -41,4 +31,18 @@ public class AudioManager : MonoBehaviour } s.source.Play(); } + + public void Stop(string name) + { + Sound s = Array.Find(sounds, sound => sound.name == name); + if (s == null) return; + s.source.Stop(); + } + + public bool isPlaying(string name) + { + Sound s = Array.Find(sounds, sound => sound.name == name); + if (s == null) return false; + return s.source.isPlaying; + } } |