Last active
August 29, 2015 14:23
-
-
Save jbasinger/d168f82316e7c1386b66 to your computer and use it in GitHub Desktop.
FireBullet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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