Weapons start_2

+ added shooting animation
+ added idle animation
This commit is contained in:
Noah4ever
2021-10-18 16:48:47 +02:00
parent 20830538db
commit c4d3f8590c
11 changed files with 1776 additions and 5 deletions

View File

@@ -6,7 +6,7 @@ public class Weapon : MonoBehaviour
{
[SerializeField] bool active = false;
[SerializeField] float damage = 0;
[SerializeField] int firerate = 0;
[SerializeField] float firerate = 0;
[SerializeField] float recoilStrength = 0;
[SerializeField] int currentAmmunition = 0;
[SerializeField] int totalAmmunition = 0;
@@ -14,11 +14,16 @@ public class Weapon : MonoBehaviour
[SerializeField] ParticleSystem smoke;
[SerializeField] GameObject bulletExit;
[SerializeField] GameObject camera;
public bool Active { get => active; set => active = value; }
private bool allowShoot = true, isShooting = false;
Animator anim;
private void Start()
{
anim = GetComponent<Animator>();
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit))
{
transform.rotation = Quaternion.Euler(0f, hit.point.y, 0f);
@@ -26,15 +31,29 @@ public class Weapon : MonoBehaviour
}
private void FixedUpdate()
{
if (Input.GetButton("Fire1"))
if (Input.GetButton("Fire") && allowShoot && currentAmmunition > 0)
{
anim.Play("USP");
isShooting = true;
StartCoroutine(fireRate());
fire();
currentAmmunition--;
}
else
{
isShooting = false;
}
if (Input.GetButton("Reload"))
{
currentAmmunition = totalAmmunition;
}
}
private void fire()
{
allowShoot = false;
flash.Play();
smoke.Play();
//smoke.Play();
RaycastHit hit;
if(Physics.Raycast(bulletExit.transform.position,bulletExit.transform.forward, out hit))
@@ -46,5 +65,14 @@ public class Weapon : MonoBehaviour
}
Instantiate(bulletImpact, hit.point, Quaternion.LookRotation(hit.normal));*/
}
}
IEnumerator fireRate()
{
allowShoot = false;
yield return new WaitForSeconds(firerate);
allowShoot = true;
}
}