diff --git a/Assets/Scenes/Level_01.unity b/Assets/Scenes/Level_01.unity index 3ef265c3a32693d774b35234f737aebcf610faab..5d9fcfe04f76a906afd42fd63234f4101dc05cb9 100644 --- a/Assets/Scenes/Level_01.unity +++ b/Assets/Scenes/Level_01.unity @@ -8753,7 +8753,11 @@ MonoBehaviour: hurtClip: {fileID: 8300000, guid: 9922a12f34d0a084aab32de985459723, type: 3} flashSpeed: 5 flashColour: {r: 1, g: 0, b: 0, a: 0.1} + weaponHandling: {fileID: 624092178} + rifle: {fileID: 1003343663} + shotgun: {fileID: 450320213} saveHandler: {fileID: 1939156179} + time: {fileID: 1987641286} --- !u!114 &624092173 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Player/PlayerHealth.cs b/Assets/Scripts/Player/PlayerHealth.cs index 44e33db6932368fcde841241837e3632a9634d5f..01cb56bb0c4b51262e0f34b84692511eedf89e86 100644 --- a/Assets/Scripts/Player/PlayerHealth.cs +++ b/Assets/Scripts/Player/PlayerHealth.cs @@ -18,11 +18,17 @@ public class PlayerHealth : MonoBehaviour, Attackable Animator anim; AudioSource playerAudio; PlayerMovement playerMovement; - Rifle playerShooting; + + public WeaponHandling weaponHandling; + public Rifle rifle; + public Shotgun shotgun; + bool isDead; bool damaged; public SaveHandler saveHandler; + public GameObject time; + void Awake() { //Mendapatkan refernce komponen @@ -30,7 +36,6 @@ public class PlayerHealth : MonoBehaviour, Attackable playerAudio = GetComponent<AudioSource>(); playerMovement = GetComponent<PlayerMovement>(); - playerShooting = GetComponentInChildren<Rifle> (); currentHealth = startingHealth; if (PlayerPrefs.HasKey("fileName")) @@ -111,7 +116,15 @@ public class PlayerHealth : MonoBehaviour, Attackable { isDead = true; - playerShooting.DisableEffects(); + if (weaponHandling.weaponIdx == 0) + { + rifle.DisableEffects(); + rifle.enabled = false; + } else if (weaponHandling.weaponIdx == 1) + { + shotgun.DisableEffects(); + shotgun.enabled = false; + } //mentrigger animasi Die anim.SetBool("Die", true); @@ -123,14 +136,22 @@ public class PlayerHealth : MonoBehaviour, Attackable //mematikan script player movement playerMovement.enabled = false; - playerShooting.enabled = false; } public void Revive() { isDead = false; - playerShooting.EnableEffects(); + if (weaponHandling.weaponIdx == 0) + { + rifle.EnableEffects(); + rifle.enabled = true; + } + else if (weaponHandling.weaponIdx == 1) + { + shotgun.EnableEffects(); + shotgun.enabled = true; + } anim.SetTrigger("Revive"); anim.SetBool("Die", false); @@ -139,7 +160,8 @@ public class PlayerHealth : MonoBehaviour, Attackable playerMovement.enabled = true; - playerShooting.enabled = true; + time.SetActive(true); + } } \ No newline at end of file diff --git a/Assets/Scripts/Quest/QuestManager.cs b/Assets/Scripts/Quest/QuestManager.cs index 642d6e3f0764ff66c35fd37302dad2d2d34828f1..98be1837c4d69e9ac7a65a6ff89ea2070ad84667 100644 --- a/Assets/Scripts/Quest/QuestManager.cs +++ b/Assets/Scripts/Quest/QuestManager.cs @@ -47,10 +47,6 @@ public class QuestManager : MonoBehaviour anim = GetComponent<Animator>(); timeProgress.text = "00:00:00"; - if (time == null) - { - time = 0f; - } questItems.Add(new QuestItem( "Kill 5 Zombunnies and 4 Zombears", diff --git a/Assets/Scripts/Save/SaveData.cs b/Assets/Scripts/Save/SaveData.cs index c68aa668a0c7d5cbc36d7dfab1d856073d9eafff..1b7faf8be1a4db36421961efed79690ded5e79d4 100644 --- a/Assets/Scripts/Save/SaveData.cs +++ b/Assets/Scripts/Save/SaveData.cs @@ -18,6 +18,7 @@ public class SaveData public int shotgun; public int sword; public int bow; + public int weaponIdx; public static SaveData getSaveData() { @@ -35,6 +36,7 @@ public class SaveData data.bow = player.GetComponent<PlayerMovement>().bow; data.score = ScoreManager.score; data.time = canvas.GetComponent<QuestManager>().getTime(); + data.weaponIdx = player.GetComponent<WeaponHandling>().weaponIdx; return data; } diff --git a/Assets/Scripts/Save/SaveHandler.cs b/Assets/Scripts/Save/SaveHandler.cs index 5dfa76aeaf8d18d52e1b6230b17b6fad06bb9262..8a2ccc82f030e90e1053b541c656909b31f08127 100644 --- a/Assets/Scripts/Save/SaveHandler.cs +++ b/Assets/Scripts/Save/SaveHandler.cs @@ -87,6 +87,7 @@ public class SaveHandler : MonoBehaviour player.GetComponent<PlayerMovement>().bow = data.bow; ScoreManager.score = data.score; questManager.setTime(data.time); + player.GetComponent<WeaponHandling>().weaponIdx = data.weaponIdx; } public Dictionary<int, Tuple<string, DateTime>> preprocessFileName(string[] files_str) diff --git a/Assets/Scripts/Player/Rifle.cs b/Assets/Scripts/Weapons/Rifle.cs similarity index 100% rename from Assets/Scripts/Player/Rifle.cs rename to Assets/Scripts/Weapons/Rifle.cs diff --git a/Assets/Scripts/Player/Rifle.cs.meta b/Assets/Scripts/Weapons/Rifle.cs.meta similarity index 100% rename from Assets/Scripts/Player/Rifle.cs.meta rename to Assets/Scripts/Weapons/Rifle.cs.meta diff --git a/Assets/Scripts/Player/Shotgun.cs b/Assets/Scripts/Weapons/Shotgun.cs similarity index 98% rename from Assets/Scripts/Player/Shotgun.cs rename to Assets/Scripts/Weapons/Shotgun.cs index 00fd1eb80334f8cf4b7f8e3956f50b50604ea723..32a8e6c405b4990cd1222576dbcf75fab5c4cde7 100644 --- a/Assets/Scripts/Player/Shotgun.cs +++ b/Assets/Scripts/Weapons/Shotgun.cs @@ -103,7 +103,6 @@ public class Shotgun : MonoBehaviour { enemyHealth.TakeDamage(damagePerShot, shootHit.point); } - Debug.Log(shootHit.point); gunLine.SetPosition(idx*2+1, shootHit.point); } else { diff --git a/Assets/Scripts/Player/Shotgun.cs.meta b/Assets/Scripts/Weapons/Shotgun.cs.meta similarity index 100% rename from Assets/Scripts/Player/Shotgun.cs.meta rename to Assets/Scripts/Weapons/Shotgun.cs.meta diff --git a/Assets/Scripts/Player/Sword.cs b/Assets/Scripts/Weapons/Sword.cs similarity index 100% rename from Assets/Scripts/Player/Sword.cs rename to Assets/Scripts/Weapons/Sword.cs diff --git a/Assets/Scripts/Player/Sword.cs.meta b/Assets/Scripts/Weapons/Sword.cs.meta similarity index 100% rename from Assets/Scripts/Player/Sword.cs.meta rename to Assets/Scripts/Weapons/Sword.cs.meta