- Home /
Question by
crazygamerdl1 · Sep 01, 2017 at 06:06 PM ·
function call
"Shoot" function not being called
Hello,
I have a gun script. There is a function that is not being called, even though I am calling the method. Here is my code:
using System.Collections; using UnityEngine;
public class Gun : MonoBehaviour {
public int clipAmmo = 30;
private int ammo;
public int playerAmmo = 270;
public float rateOfFire = 1;
bool canFire = true;
public bool isFullyAutomatic = true;
void Start () {
ammo = clipAmmo;
}
void Update () {
if (isFullyAutomatic)
{
if (Input.GetButton("Fire1"))
{
if (canFire)
{
canFire = false;
Shoot();
}
}
}
}
IEnumerator Shoot()
{
Debug.Log("PEW");
yield return new WaitForSeconds(rateOfFire);
canFire = true;
}
}
Why is it not being called?
Comment
Best Answer
Answer by TheSOULDev · Sep 01, 2017 at 06:49 PM
Because you can't just call an IEnumerator like that, use StartCoroutine(Shoot())
.
I cant believe I forgot that. Of all the things I could have forgotten, I forgot that.