I’m trying to make an archery game, but I can’t figure out how to make yield waitforseconds work so that there is a delay between launching arrows. It keeps saying that there is a parser error and that it doesn’t recognize yield in this context.
using UnityEngine;
using System.Collections;
public class spawnArrows : MonoBehaviour {
public GameObject arrow;
private bool allowFire = true;
// Use this for initialization
void Start () {
if ((Input.GetAxis("Fire1")!=0)&&(allowFire)) {
StartCoroutine (fireCoroutine ());
}
}
IEnumerator fireCoroutine(){
allowFire = false;
Instantiate(original: arrow);
yield WaitForSeconds (5);
allowFire = true;
}
}
Your StartCoroutine is not enough. You are instead on line 11 meant to do:
yield StartCoroutine (fireCoroutine ());
that yield WaitForSeconds is useless if your StartCoroutine does not have a yield itself.
Yword
3
The correct syntax should be:
yield return new WaitForSeconds (timeDelay);