From ec12df498af42f6af0af79382133f6a8cee14819 Mon Sep 17 00:00:00 2001
From: fdavin <fransdavin19@gmail.com>
Date: Sat, 15 Apr 2023 15:34:22 +0700
Subject: [PATCH] fix: weapon handling

---
 Assets/Audio/Effects/crossbow shot.mp3      |  3 +++
 Assets/Audio/Effects/crossbow shot.mp3.meta | 22 ++++++++++++++++
 Assets/BowShooting.cs                       |  5 +++-
 Assets/WeaponHandling.cs                    | 28 +++++++++++++++++++++
 4 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 Assets/Audio/Effects/crossbow shot.mp3
 create mode 100644 Assets/Audio/Effects/crossbow shot.mp3.meta

diff --git a/Assets/Audio/Effects/crossbow shot.mp3 b/Assets/Audio/Effects/crossbow shot.mp3
new file mode 100644
index 0000000..73f5666
--- /dev/null
+++ b/Assets/Audio/Effects/crossbow shot.mp3	
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:9b3a84980ea5cba678a51b4801d0ad8fe2613c54f9ff0aea9f49bd65b075e46b
+size 16320
diff --git a/Assets/Audio/Effects/crossbow shot.mp3.meta b/Assets/Audio/Effects/crossbow shot.mp3.meta
new file mode 100644
index 0000000..90c7c7a
--- /dev/null
+++ b/Assets/Audio/Effects/crossbow shot.mp3.meta	
@@ -0,0 +1,22 @@
+fileFormatVersion: 2
+guid: 1f660a7f70aaaf94e94019c8a23e3114
+AudioImporter:
+  externalObjects: {}
+  serializedVersion: 6
+  defaultSettings:
+    loadType: 0
+    sampleRateSetting: 0
+    sampleRateOverride: 44100
+    compressionFormat: 1
+    quality: 1
+    conversionMode: 0
+  platformSettingOverrides: {}
+  forceToMono: 0
+  normalize: 1
+  preloadAudioData: 1
+  loadInBackground: 0
+  ambisonic: 0
+  3D: 1
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Assets/BowShooting.cs b/Assets/BowShooting.cs
index 3039718..4e01728 100644
--- a/Assets/BowShooting.cs
+++ b/Assets/BowShooting.cs
@@ -14,9 +14,11 @@ public class BowShooting : MonoBehaviour
     public float maxRotation;
     public float angle;
     private bool fire;
+    AudioSource audioSource;
     
     void Start()
     {
+        audioSource = GetComponent<AudioSource>();
         firePowerSpeed = 5;
         bow.Reload();
     }
@@ -33,11 +35,12 @@ public class BowShooting : MonoBehaviour
         }
         if (fire && firePowerSpeed < maxPower)
         {
-            firePowerSpeed += Time.deltaTime * firePowerSpeed;
+            firePowerSpeed += Time.deltaTime * firePowerSpeed/2;
         }
         if (fire && Input.GetButtonUp("Fire1"))
         {
             bow.Shoot(firePowerSpeed);
+            audioSource.Play();
             firePowerSpeed = 0;
             fire = false;
         }
diff --git a/Assets/WeaponHandling.cs b/Assets/WeaponHandling.cs
index d4e073b..3dd18ef 100644
--- a/Assets/WeaponHandling.cs
+++ b/Assets/WeaponHandling.cs
@@ -19,6 +19,34 @@ public class WeaponHandling : MonoBehaviour
     // Update is called once per frame
     void Update()
     {
+        if (weaponIdx == 0){
+            Rifle.SetActive(true);
+            RifleEnd.SetActive(true);
+            Shotgun.SetActive(false);
+            Bow.SetActive(false);
+            Sword.SetActive(false);
+        }
+        else if (weaponIdx == 1){
+            Rifle.SetActive(false);
+            RifleEnd.SetActive(false);
+            Shotgun.SetActive(true);
+            Bow.SetActive(false);
+            Sword.SetActive(false);
+        }
+        else if (weaponIdx == 2){
+            Rifle.SetActive(false);
+            RifleEnd.SetActive(false);
+            Shotgun.SetActive(false);
+            Bow.SetActive(false);
+            Sword.SetActive(true);
+        }
+        else if (weaponIdx == 3){
+            Rifle.SetActive(false);
+            RifleEnd.SetActive(false);
+            Shotgun.SetActive(false);
+            Bow.SetActive(true);
+            Sword.SetActive(false);
+        }
         if (Input.GetKeyDown("1"))
         {
             weaponIdx = 0;
-- 
GitLab