montzions ui pausenmenü ui lebns ui nachladen pausen menü neues digsein
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class WeaponReload : MonoBehaviour
|
||||
{
|
||||
[Header("Munitionseinstellungen")]
|
||||
public int maxAmmo = 30; // Maximale Munition im Magazin
|
||||
public int currentAmmo; // Aktuelle Munition
|
||||
public float reloadTime = 1.5f; // Wie lange das Nachladen dauert (in Sekunden)
|
||||
|
||||
private bool isReloading = false; // Verhindert Doppelklicks / Aktionen während des Nachladens
|
||||
|
||||
void Start()
|
||||
{
|
||||
currentAmmo = maxAmmo; // Beim Start ist das Magazin voll
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Während nachgeladen wird, keine Aktionen zulassen
|
||||
if (isReloading)
|
||||
return;
|
||||
|
||||
// --- PUNKT 1: Auslösen auf R ODER wenn Magazin leer ist ---
|
||||
// 1. Manuelles Nachladen mit R (nur wenn Magazin nicht schon voll ist)
|
||||
if (Input.GetKeyDown(KeyCode.R) && currentAmmo < maxAmmo)
|
||||
{
|
||||
StartCoroutine(Reload());
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Automatisches Nachladen beim Schießen, wenn das Magazin leer (<= 0) ist
|
||||
if (Input.GetButtonDown("Fire1"))
|
||||
{
|
||||
if (currentAmmo > 0)
|
||||
{
|
||||
Shoot();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Magazin ist leer -> automatisch nachladen!
|
||||
StartCoroutine(Reload());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Shoot()
|
||||
{
|
||||
// Nur schießen, wenn das Pausemenü NICHT offen ist
|
||||
if (PausenManager.GameIsPaused) return;
|
||||
|
||||
currentAmmo--;
|
||||
Debug.Log("Schuss gefeuert! Verbleibende Munition: " + currentAmmo);
|
||||
|
||||
// Hier deinen normalen Schuss-Code einfügen (Raycast, Bullet-Prefab, Ton etc.)
|
||||
}
|
||||
|
||||
// Coroutine für die Nachlade-Verzögerung
|
||||
IEnumerator Reload()
|
||||
{
|
||||
isReloading = true;
|
||||
Debug.Log("Nachladen gestartet...");
|
||||
|
||||
// Hier könntest du z.B. eine Nachlade-Animation oder einen Sound abspielen:
|
||||
// animator.SetTrigger("Reload");
|
||||
|
||||
// Warten, bis die Nachladezeit abgelaufen ist
|
||||
yield return new WaitForSeconds(reloadTime);
|
||||
|
||||
// --- PUNKT 2: Munition wieder voll wenn fertig ---
|
||||
currentAmmo = maxAmmo;
|
||||
|
||||
isReloading = false;
|
||||
Debug.Log("Nachladen abgeschlossen! Munition wieder voll: " + currentAmmo);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user