using UnityEngine;
[CreateAssetMenu(menuName = "Classes/Mercenary")]
public class MercenaryClass : ClassBaseType
{
[SerializeField] private float damage;
[SerializeField] private float recoil;
[SerializeField] private float refillTimeTotal;
private float timerReffil = 0;
[SerializeField] private uint maxBullets;
public uint numberOfBullets;
public GameObject bulletPrefab;
private Rigidbody rb;
[SerializeField] private string abilityKey;
SoundsManager sM;
AudioSource audioSource;
public override void Starter(GameObject source)
{
//base.Starter(source);
dead = false;
currentHp = hp;
rb = source.GetComponent<Rigidbody>();
timerReffil = 0;
GameObject t = GameObject.Find("AudioManager");
if(t) sM = t.GetComponent<SoundsManager>();
audioSource= source.GetComponent<AudioSource>();
}
public override void Cooldown()
{
if (timerReffil > 0) timerReffil -= Time.deltaTime;
if(timerReffil <= 0 && numberOfBullets == 0)
{
numberOfBullets = maxBullets;
}
}
public override void Ability(StatusEffects se)
{
if (Input.GetButtonDown(abilityKey))
{
Debug.Log(numberOfBullets);
if (numberOfBullets > 0)
{
if (sM) sM.PlaySoundEffect("Shotgun", audioSource);
Vector3 dir = Vector3.Normalize(Input.mousePosition - new Vector3(Screen.width / 2, Screen.height / 2, 0));
GameObject bullet = Instantiate(bulletPrefab, se.transform.position + (dir * 2), Quaternion.identity);
bullet.GetComponent<Rigidbody>().velocity = dir * 30;
rb.velocity += -dir * 30;
numberOfBullets -= 1;
if (numberOfBullets <= 0) {
if (sM) sM.PlaySoundEffect("Reload", audioSource);
timerReffil = refillTimeTotal;
}
}
}
}
}