From df37d141204c52e2bfe9f3f72561574678827ca3 Mon Sep 17 00:00:00 2001 From: pbg2h23akl Date: Mon, 1 Jul 2024 16:37:19 +0200 Subject: [PATCH] Gun Reloads now if empty --- .../Assets/PrefabsKevin/Gun/Gun.prefab | 2 + .../Assets/Scenes/KevinSceneGun.unity | 58 ------------------- .../Scripts/ScriptsKevin/WeaponScript.cs | 33 ++++++++++- 3 files changed, 32 insertions(+), 61 deletions(-) diff --git a/Plunderblock/Assets/PrefabsKevin/Gun/Gun.prefab b/Plunderblock/Assets/PrefabsKevin/Gun/Gun.prefab index 1803284..c249bb2 100644 --- a/Plunderblock/Assets/PrefabsKevin/Gun/Gun.prefab +++ b/Plunderblock/Assets/PrefabsKevin/Gun/Gun.prefab @@ -238,3 +238,5 @@ MonoBehaviour: m_EditorClassIdentifier: spawnpoint: {fileID: 3929927056536112425} bullet: {fileID: 939049122039926632, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} + dataBullet: {fileID: 11400000, guid: cafd241bae342f446ae8141cc5d72daf, type: 2} + reloadTime: 3 diff --git a/Plunderblock/Assets/Scenes/KevinSceneGun.unity b/Plunderblock/Assets/Scenes/KevinSceneGun.unity index 159b719..eaa2fac 100644 --- a/Plunderblock/Assets/Scenes/KevinSceneGun.unity +++ b/Plunderblock/Assets/Scenes/KevinSceneGun.unity @@ -789,63 +789,6 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 940378051} m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} ---- !u!1001 &1030353343 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - serializedVersion: 3 - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 939049122039926632, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} - propertyPath: m_Name - value: Bullet - objectReference: {fileID: 0} - - target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} - propertyPath: m_LocalPosition.x - value: 5.431 - objectReference: {fileID: 0} - - target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_RemovedGameObjects: [] - m_AddedGameObjects: [] - m_AddedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3} --- !u!1 &1062964497 GameObject: m_ObjectHideFlags: 0 @@ -1984,4 +1927,3 @@ SceneRoots: - {fileID: 1513164528} - {fileID: 1124830199} - {fileID: 829478755} - - {fileID: 1030353343} diff --git a/Plunderblock/Assets/Scripts/ScriptsKevin/WeaponScript.cs b/Plunderblock/Assets/Scripts/ScriptsKevin/WeaponScript.cs index 4d28171..2acb689 100644 --- a/Plunderblock/Assets/Scripts/ScriptsKevin/WeaponScript.cs +++ b/Plunderblock/Assets/Scripts/ScriptsKevin/WeaponScript.cs @@ -7,17 +7,44 @@ public class WeaponScript : MonoBehaviour public GameObject spawnpoint; public GameObject bullet; - - private void shoot(){ + + public DataBullet dataBullet; + + private int ammo; + private bool isReloading = false; + private float time = 0; + + public float reloadTime; + + public void reload(){ + if(ammo == 0){ + isReloading = true; + } + if(isReloading){ + time += Time.deltaTime; + if(time > reloadTime){ + ammo = dataBullet.ammo; + time = 0; + isReloading = false; + } + } + } + public void shoot(){ + if(ammo != 0){ if(Input.GetKeyDown(KeyCode.Mouse0)){ Instantiate(bullet,spawnpoint.transform.position,transform.rotation); + ammo--; + } + }else{ + reload(); } } void Start() { - + dataBullet = GetComponentInChildren(); + ammo = dataBullet.ammo; } // Update is called once per frame