You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RatAttack2D/Assets/Scripts/Weapon.cs

39 lines
987 B

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon : MonoBehaviour
{
[SerializeField] private int maxAmmo;
[SerializeField] private float shootSpeed;
[SerializeField] private int damage;
[SerializeField] private bool fullAuto;
[SerializeField] private GameObject Bullet;
private int Ammo;
private bool shootDone;
private float Wait;
private void Start()
{
Ammo = maxAmmo;
}
public void shoot()
{
if(Ammo == 0 || Wait > 0 || shootDone && !fullAuto)
{
return;
}
if(!fullAuto)
{
shootDone = true;
}
Wait += shootSpeed;
GameObject bullet = GameObject.Instantiate(Bullet, transform.position, transform.rotation);
bullet.GetComponent<Bullet>().setDmg = damage;
}
private void Update()
{
Wait -= Time.deltaTime;
Wait = Mathf.Clamp(Wait, 0, shootSpeed);
}
}