diff --git a/Plunderblock/Assets/PrefabsJan/Player.prefab b/Plunderblock/Assets/PrefabsJan/Player.prefab index a460d87..af9513a 100644 --- a/Plunderblock/Assets/PrefabsJan/Player.prefab +++ b/Plunderblock/Assets/PrefabsJan/Player.prefab @@ -294,6 +294,85 @@ BoxCollider: serializedVersion: 3 m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} +--- !u!1 &7566297578841152737 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2355847910073875648} + - component: {fileID: 3332157730834607231} + - component: {fileID: 1464316800582670505} + m_Layer: 10 + m_Name: Ammo + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2355847910073875648 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7566297578841152737} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: -0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 8234077612602293382} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: -418, y: -275} + m_SizeDelta: {x: 134.5, y: 109.16} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &3332157730834607231 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7566297578841152737} + m_CullTransparentMesh: 1 +--- !u!114 &1464316800582670505 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7566297578841152737} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 46 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 6 + m_MaxSize: 60 + m_Alignment: 0 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: 0 --- !u!1 &8948127678283011642 GameObject: m_ObjectHideFlags: 0 @@ -483,6 +562,10 @@ PrefabInstance: propertyPath: m_Layer value: 10 objectReference: {fileID: 0} + - target: {fileID: 4766397035718395917, guid: abb3f2146f967be4e9dfd6069915f42c, type: 3} + propertyPath: dataBullet + value: + objectReference: {fileID: 11400000, guid: cafd241bae342f446ae8141cc5d72daf, type: 2} - target: {fileID: 5727695039551963900, guid: abb3f2146f967be4e9dfd6069915f42c, type: 3} propertyPath: m_LocalPosition.z value: -0 @@ -561,7 +644,10 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] - m_AddedGameObjects: [] + m_AddedGameObjects: + - targetCorrespondingSourceObject: {fileID: 4822466156586256155, guid: abb3f2146f967be4e9dfd6069915f42c, type: 3} + insertIndex: -1 + addedObject: {fileID: 2355847910073875648} m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: abb3f2146f967be4e9dfd6069915f42c, type: 3} --- !u!4 &7059315404903924766 stripped @@ -569,6 +655,11 @@ Transform: m_CorrespondingSourceObject: {fileID: 5863193481701293955, guid: abb3f2146f967be4e9dfd6069915f42c, type: 3} m_PrefabInstance: {fileID: 3506481795036953501} m_PrefabAsset: {fileID: 0} +--- !u!224 &8234077612602293382 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 4822466156586256155, guid: abb3f2146f967be4e9dfd6069915f42c, type: 3} + m_PrefabInstance: {fileID: 3506481795036953501} + m_PrefabAsset: {fileID: 0} --- !u!1001 &7466933759953658907 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Plunderblock/Assets/Scripts/ScriptsKevin/UI_Manager.cs b/Plunderblock/Assets/Scripts/ScriptsKevin/UI_Manager.cs new file mode 100644 index 0000000..7e66d8e --- /dev/null +++ b/Plunderblock/Assets/Scripts/ScriptsKevin/UI_Manager.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using Unity.VisualScripting; +using UnityEngine; +using UnityEngine.UI; + +public class UI_Manager : MonoBehaviour +{ + private Text[] textFelder; + private Transform canvas; + private int maxAmmo; + public DataBullet dataBullet; + public void killCount(int addedScore){ + int summe = int.Parse(textFelder[0].text) + addedScore; + textFelder[0].text = "" + summe; + } + public void ammoDown(){ + String[] stringparts = textFelder[1].text.Split('/'); + int aktuellAmmo = int.Parse(stringparts[0]); + textFelder[1].text = aktuellAmmo - 1 + "/" + maxAmmo; + } + public void ammoReset(){ + textFelder[1].text = maxAmmo + "/" + maxAmmo; + } + void Start() + { + maxAmmo = dataBullet.ammo; + canvas = this.gameObject.GetComponentInChildren(); + textFelder = canvas.GetComponentsInChildren(); + textFelder[0].text = "0"; + ammoReset(); + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Plunderblock/Assets/UI_Manager.cs.meta b/Plunderblock/Assets/Scripts/ScriptsKevin/UI_Manager.cs.meta similarity index 100% rename from Plunderblock/Assets/UI_Manager.cs.meta rename to Plunderblock/Assets/Scripts/ScriptsKevin/UI_Manager.cs.meta diff --git a/Plunderblock/Assets/Scripts/ScriptsKevin/WeaponScript.cs b/Plunderblock/Assets/Scripts/ScriptsKevin/WeaponScript.cs index a95c47f..0b6e43c 100644 --- a/Plunderblock/Assets/Scripts/ScriptsKevin/WeaponScript.cs +++ b/Plunderblock/Assets/Scripts/ScriptsKevin/WeaponScript.cs @@ -9,6 +9,7 @@ public class WeaponScript : MonoBehaviour public GameObject bullet; public DataBullet dataBullet; + public UI_Manager uI_Manager; private int ammo; private bool isReloading = false; @@ -27,23 +28,23 @@ public class WeaponScript : MonoBehaviour time += Time.deltaTime; if(time > reloadTime){ ammo = dataBullet.ammo; + uI_Manager.ammoReset(); time = 0; isReloading = false; } } } public void shoot(){ - if(ammo != 0){ - if(delayOver){ - if(Input.GetKeyDown(KeyCode.Mouse0)){ + if(ammo != 0 && delayOver){ + if(Input.GetKeyDown(KeyCode.Mouse0)){ muzzle.gameObject.SetActive(true); //muzzle.Play(); Instantiate(bullet,spawnpoint.transform.position,spawnpoint.transform.rotation); ammo--; + uI_Manager.ammoDown(); delay = 0; delayOver = false; - } - } + } } } public void checkDelay(){ @@ -59,6 +60,7 @@ public class WeaponScript : MonoBehaviour ammo = dataBullet.ammo; muzzle = GetComponentInChildren(); spawnpoint = GameObject.Find("Player/PlayerView/BulletSpawnpoint"); + uI_Manager = GameObject.FindGameObjectWithTag("Manager").GetComponent(); } // Update is called once per frame diff --git a/Plunderblock/Assets/UI_Manager.cs b/Plunderblock/Assets/UI_Manager.cs deleted file mode 100644 index 4abe3ee..0000000 --- a/Plunderblock/Assets/UI_Manager.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using UnityEngine; -using UnityEngine.UI; - -public class UI_Manager : MonoBehaviour -{ - private Text anzahlKills; - - private Transform canvas; - - public void killCount(int addedScore){ - int summe = int.Parse(anzahlKills.text) + addedScore; - anzahlKills.text = "" + summe; - } - void Start() - { - canvas = this.gameObject.GetComponentInChildren(); - anzahlKills = canvas.GetComponentInChildren(); - anzahlKills.text = "0"; - } - - // Update is called once per frame - void Update() - { - - } -}