From 1d7d26b402d273f56eec7dd308283e373108139a Mon Sep 17 00:00:00 2001
From: girvinjunod <girvinjunod@gmail.com>
Date: Sat, 9 Apr 2022 22:17:05 +0700
Subject: [PATCH] fix: crit audio not playing

---
 Survival Shooter/Assets/Prefabs/Bullet.prefab         |  2 +-
 Survival Shooter/Assets/Scripts/Bullet/Bullet.cs      |  7 ++++---
 .../Assets/Scripts/Player/PlayerShooting.cs           | 11 ++++++++++-
 Survival Shooter/Assets/Scripts/UpgradeMenu.cs        |  6 +++---
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/Survival Shooter/Assets/Prefabs/Bullet.prefab b/Survival Shooter/Assets/Prefabs/Bullet.prefab
index 6c2b06f..12abbcd 100644
--- a/Survival Shooter/Assets/Prefabs/Bullet.prefab	
+++ b/Survival Shooter/Assets/Prefabs/Bullet.prefab	
@@ -144,7 +144,7 @@ AudioSource:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 8946891882775703378}
-  m_Enabled: 1
+  m_Enabled: 0
   serializedVersion: 4
   OutputAudioMixerGroup: {fileID: 0}
   m_audioClip: {fileID: 8300000, guid: f4726624026e4dc44a180953882a028d, type: 3}
diff --git a/Survival Shooter/Assets/Scripts/Bullet/Bullet.cs b/Survival Shooter/Assets/Scripts/Bullet/Bullet.cs
index 4a7de02..5635112 100644
--- a/Survival Shooter/Assets/Scripts/Bullet/Bullet.cs	
+++ b/Survival Shooter/Assets/Scripts/Bullet/Bullet.cs	
@@ -19,7 +19,7 @@ public class Bullet : MonoBehaviour, IPooledObject
     bool hasHit = false;
     PlayerShooting playerShooting;
     GameObject player;
-    AudioSource critAudio;
+    // AudioSource critAudio;
 
     public int bulletCritChance = 0;
 
@@ -32,7 +32,7 @@ public class Bullet : MonoBehaviour, IPooledObject
         damage = playerShooting.damagePerShot;
         newPos = transform.position;
         oldPos = newPos;
-        critAudio = GetComponent<AudioSource>();
+        // critAudio = GetComponent<AudioSource>();
         bulletCritChance = PlayerShooting.critChance;
         hasHit = false;
         timer = 0;
@@ -108,7 +108,8 @@ public class Bullet : MonoBehaviour, IPooledObject
             if (rand < bulletCritChance)
             {
                 Debug.Log("Crit");
-                critAudio.Play();
+                // critAudio.Play();
+                playerShooting.playCritAudio();
                 isCrit = true;
             }
             if (isCrit)
diff --git a/Survival Shooter/Assets/Scripts/Player/PlayerShooting.cs b/Survival Shooter/Assets/Scripts/Player/PlayerShooting.cs
index 84e218f..23f1fd5 100644
--- a/Survival Shooter/Assets/Scripts/Player/PlayerShooting.cs	
+++ b/Survival Shooter/Assets/Scripts/Player/PlayerShooting.cs	
@@ -16,7 +16,9 @@ public class PlayerShooting : MonoBehaviour
     int shootableMask;
     ParticleSystem gunParticles;
     LineRenderer gunLine;
+    AudioSource[] gunAudioArr;
     AudioSource gunAudio;
+    AudioSource critAudio;
     Light gunLight;
     float effectsDisplayTime = 0.2f;
     ObjectPooler objectPooler;
@@ -31,7 +33,9 @@ public class PlayerShooting : MonoBehaviour
         shootableMask = LayerMask.GetMask("Shootable");
         gunParticles = GetComponent<ParticleSystem>();
         gunLine = GetComponent<LineRenderer>();
-        gunAudio = GetComponent<AudioSource>();
+        gunAudioArr = GetComponents<AudioSource>();
+        gunAudio = gunAudioArr[0];
+        critAudio = gunAudioArr[1];
         gunLight = GetComponent<Light>();
 
         critChance = 0;
@@ -130,5 +134,10 @@ public class PlayerShooting : MonoBehaviour
         }
     }
 
+    public void playCritAudio()
+    {
+        critAudio.Play();
+    }
+
 
 }
\ No newline at end of file
diff --git a/Survival Shooter/Assets/Scripts/UpgradeMenu.cs b/Survival Shooter/Assets/Scripts/UpgradeMenu.cs
index d7b2b3f..8329160 100644
--- a/Survival Shooter/Assets/Scripts/UpgradeMenu.cs	
+++ b/Survival Shooter/Assets/Scripts/UpgradeMenu.cs	
@@ -30,7 +30,7 @@ public class UpgradeMenu : MonoBehaviour
     private int numUpgrades = 0;
     private int maxNumUpgrades = 6;
 
-    private int perTime = 10;
+    private int perTime = 20;
 
     GameObject player;
     PlayerShooting playerShooting;
@@ -39,8 +39,8 @@ public class UpgradeMenu : MonoBehaviour
     {
         // time = 0;
         // Time.timeScale = 0f;
-        player = GameObject.FindGameObjectWithTag ("Player");
-        playerShooting = player.GetComponentInChildren <PlayerShooting> ();
+        player = GameObject.FindGameObjectWithTag("Player");
+        playerShooting = player.GetComponentInChildren<PlayerShooting>();
     }
 
     // void OnEnable()
-- 
GitLab