so i’m quite new to unity scripting and was trying to add a delay to a gun shooting script i have. its for a crappy vr project and so I managed to make it work with the vive controller but the bullets come out too fast, was wondering if someone could help me IN DETAIL with this, thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnObjectOnButtonPressedScript : MonoBehaviour
{
public GameObject Bullet_Emitter;
public VRTK.VRTK_ControllerEvents controllerEvents;
public GameObject Bullet;
public float Bullet_Forward_Force;
this is what I came up with using the invoke command, im pretty sure I did something wrong because I get quite a few errors such as ‘Keyword void cannot be used in this context’ and unexpected symbols.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnObjectOnButtonPressedScript : MonoBehaviour
{
public GameObject Bullet_Emitter;
public VRTK.VRTK_ControllerEvents controllerEvents;
public GameObject Bullet;
public float Bullet_Forward_Force;
To add a wait function to your script, you will need to use an IEnumerator function.
I believe this is the script you need.
IEnumerator wait() {
// The wait function in the IEnumerator
yield return new WaitForSeconds(2);
}
void example() {
// Do the function
StartCoroutine(wait());
}