trying to make a gun programming, everything is done execpt for the gun shooting being automatic.
[Header("Gun Stats")]
public float dammage, range, reloadtime, spread;
public int magazinesize;
int bulletsleft, bulletShot;
public float firerate;
[Header("Bools")]
bool Realoding, HoldShoot, ReadyShoot, AUTO;
public bool NOTauto;
[Header("refrences")]
private Camera cam;
public Transform attackpoint;
public LayerMask WhatIsDammageble;
public TextMeshProUGUI text;
// Update is called once per frame
void Awake()
{
cam = GetComponent<LookAround>().cam;
bulletsleft = magazinesize;
text.SetText(bulletsleft + "/" + magazinesize);
ReadyShoot = true;
}
void Update()
{
Debug.Log("kysnowwwwww");
text.SetText(bulletsleft + "/" + magazinesize);
}
public virtual void ShootFuction()
{
if (Realoding == false && bulletsleft > 0 && ReadyShoot == true)
{
text.SetText(bulletsleft + "/" + magazinesize);
ReadyShoot = false;
RaycastHit hit;
Ray raypos = new Ray(cam.transform.position, cam.transform.forward);
if (Physics.Raycast(raypos, out hit, range))
{
Debug.Log("HIT" + hit.collider.gameObject.name);
IDammagble damageable = hit.collider.GetComponent<IDammagble>();
if(damageable != null)
{
damageable.Dammage(dammage);
}
}
bulletsleft--;
Invoke("ResetShot", firerate);
}
}
public virtual void Shoot()
{
if (NOTauto == false)
{
ShootFuction();
}
else
InvokeRepeating("ShootFuction", 0 ,firerate);
Debug.Log("auto");
}
public void StopShooting()
{
Debug.Log("cancel");
CancelInvoke("ShootFuction");
ReadyShoot = true;
}
public virtual void ResetShot()
{
ReadyShoot = true;
Debug.Log("is reaady to shoot");
}
public void Reload()
{ if (bulletsleft < magazinesize)
{
Realoding = true;
StartCoroutine(Realodtime());
Debug.Log("beggining Realoaidng");
}
}
public IEnumerator Realodtime()
{
yield return new WaitForSeconds(reloadtime);
Realoding = false;
bulletsleft = magazinesize;
Debug.Log("finnished Realoding");
text.SetText(bulletsleft + "/" + magazinesize);
}
}