UI Manager erweiter // Ammo UI added funktional tüchtig

This commit is contained in:
klikev
2024-07-09 13:37:35 +02:00
parent dd1c87c948
commit b3d9b99639
5 changed files with 141 additions and 36 deletions

View File

@@ -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<Transform>();
textFelder = canvas.GetComponentsInChildren<Text>();
textFelder[0].text = "0";
ammoReset();
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1271dbd420eb5b14dae4b24f833bb965
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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<ParticleSystem>();
spawnpoint = GameObject.Find("Player/PlayerView/BulletSpawnpoint");
uI_Manager = GameObject.FindGameObjectWithTag("Manager").GetComponent<UI_Manager>();
}
// Update is called once per frame