Skip to content

Instantly share code, notes, and snippets.

@jbasinger
Last active August 29, 2015 14:23
Show Gist options
  • Save jbasinger/d168f82316e7c1386b66 to your computer and use it in GitHub Desktop.
Save jbasinger/d168f82316e7c1386b66 to your computer and use it in GitHub Desktop.
FireBullet
using UnityEngine;
using System.Collections;
public class FireBullet : MonoBehaviour {
public GameObject bullet;
public float maxCoolDown;
private float timer;
private bool canShoot;
// Use this for initialization
void Start () {
timer = maxCoolDown;
canShoot = true;
}
// Update is called once per frame
void Update () {
timer = timer - Time.deltaTime;
if(timer <= 0){
canShoot = true;
}
if(Input.GetKey(KeyCode.Space) && canShoot){
Instantiate(bullet,
this.transform.position,
Quaternion.identity);
canShoot = false;
timer = maxCoolDown;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment