How do I put a delay on a gunshot script I have an if statement playing audio shooting a bullet and showing a one shot particle instance.
Perhaps try using the Invoke function? Or yield...
http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.Invoke.html Regarding the Invoke function
http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html Explaining yield
Use coroutines! In C# you would get something like:
public AudioClip bulletSound;
bool isFiring = false;
void Update() {
// ...
if (Input.GetButton("Fire1") && !isFiring) {
StartCoroutine(COFire());
}
// ...
}
IEnumerator COFire() {
isFiring = true;
yield return new WaitForSeconds(0.1f); // trigger delay
// create bullet and flash effect...
yield return 0; // wait 1 frame
// stop flash
yield return new WaitForSeconds(0.05f); // wait 0.05seconds
AudioSource.PlayClipAtPoint(bulletSound, transform.position);
yield return new WaitForSeconds(0.1f); // extra delay before you can shoot again
isFiring = false;
}