Added gun shoot event and recoil

This commit is contained in:
2024-12-08 11:56:39 +01:00
parent f597af454a
commit 10b694496b
62 changed files with 11377 additions and 7486 deletions

View File

@@ -0,0 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class Gun : MonoBehaviour
{
public UnityEvent onGunShoot;
public float fireCoolDown;
public bool automatic;
private float currentCooldown;
void Start()
{
currentCooldown = fireCoolDown;
}
void Update()
{
if(automatic)
{
if(Input.GetMouseButton(0))
{
if(currentCooldown <= 0f)
{
//if not null (?)
onGunShoot?.Invoke();
currentCooldown = fireCoolDown;
}
}
}
else
{
if(Input.GetMouseButtonDown(0))
{
if(currentCooldown <= 0f)
{
//if not null (?)
onGunShoot?.Invoke();
currentCooldown = fireCoolDown;
}
}
}
currentCooldown -= Time.deltaTime;
}
}