Set a delay for firing
Current I'm trying to rework someones template as a project for a game. Current the fire rate of the guns is basically as fast as you can hit the fire button. After looking into it I think I can set a delay? Please help I'm quite the noob when it comes to coding
the current code for weapon behaviour:
public class weaponBehaviour : usableObjectScript {
[Tooltip("ammo prefab")] public GameObject ammo;
[Tooltip("number of ammo")] public int ammoNumber;
[Tooltip("shoot power")] public float shootPower;
[Tooltip("animator state")] public int fightState;
[HideInInspector] public List<GameObject> ammunition; // list of an ammo
// Use this for initialization
void Start () {
prepareAmmo ();
prepareObject ();
StartCoroutine ("bulletdellay");
}
// Update is called once per frame
void FixedUpdate () {
}
void prepareAmmo()
{
ammunition = new List<GameObject>(); // creates ammo list
for (int i = 0; i < ammoNumber - 1; i++)
{
GameObject newAmmo = Instantiate(ammo, Vector3.zero, Quaternion.identity) as GameObject; // creates new ammo
ammunition.Add(newAmmo); // puts new ammo in array
newAmmo.SetActive(false); // disables ammo
}
}
public override void checkFighter (GameObject fighter) // checks for fighter
{
if (fighter.gameObject.layer == 8 || fighter.gameObject.layer == 9)
{
fighter.gameObject.GetComponent<fighterScript>().use(gameObject); // fighter takes weapon
gameObject.SetActive (false); // disable gameObject
}
}
public class ExampleClass : MonoBehaviour {
public Transform bulletPrefab;
void Start() {
Transform bullet = Instantiate(bulletPrefab) as Transform;
Physics2D.IgnoreCollision(bullet.GetComponent<Collider2D>(), GetComponent<Collider2D>());
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Getting a timer to go to 0 1 Answer
I need a "loop" timer that disables a action until the timer resets. 0 Answers
Countdown timer... 2 Answers