Files
No-Time-To-Rest/Assets/Scripts/Player/Pistol.cs
T
KOSMOGOR f899107d08 update: player prefab
fix: pistol not firing with higher fire rate
2025-03-17 15:36:15 +03:00

22 lines
611 B
C#

using UnityEngine;
public class Pistol : Weapon
{
public GameObject projectilePrefab;
public Transform spawnPosition;
public float fireRate = 1f;
[SerializeField] float currentDelay = 0;
public override void Shoot(bool keyDown, bool keyHold) {
if (keyDown && (fireRate == 0 || currentDelay >= 1 / fireRate)) {
Instantiate(projectilePrefab, spawnPosition.position, spawnPosition.rotation);
currentDelay = 0;
}
}
void Update() {
if (fireRate != 0) currentDelay = Mathf.Clamp(currentDelay += Time.deltaTime, 0, 1 / fireRate);
}
}