The name "yield" does not exist in current content

Im trying to make a delay between firing of my vehicle turret but it always throws me
The name “yield” does not exist in current content

Code:
using UnityEngine;
using System.Collections;

public class Turret : MonoBehaviour {
	Object emitter;
	public GameObject emitter2;
	public ExplosionEmitter emitter3;
	public Object obj;
	
	// Use this for initialization
	void Start () {
		emitter = Instantiate ( obj, transform.position, Quaternion.identity);
		emitter2 = (GameObject)emitter;
	    emitter2.transform.parent = transform;
		emitter2.transform.Translate(-8, 0, 0);
	}

	void Update () {
	float rot = Input.GetAxis ("test");
	transform.Rotate (Vector3.back * (rot * 5));
	
	while (Input.GetKeyDown("b"))
	{
	StopCoroutine("Fire");
     StartCoroutine("Fire");
    }
	
	}
	IEnumerator Fire ()
	{
	        yield.WaitForSeconds(0.5);
			audio.Play ();
			emitter2.particleSystem.Play ();
	}
}

2 Answers

2

yield.WaitForSeconds(0.5);

should be

yield return new WaitForSeconds(0.5);

In C#, you actually do it this way:

yield return new WaitForSeconds(0.5f);

Also, it’s never a bad idea to look at the scripting reference / documentation:

WaitForSeconds

:wink: