Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- var bulletObject: GameObject;
- var canShoot: boolean;
- var currentClip: int;
- var extraAmmo: int;
- var canReload: boolean;
- var difference: int;
- function Start () {
- canShoot = true;
- currentClip = 5;
- extraAmmo = 20;
- }
- function Update () {
- booleans();
- if(canReload == true){
- if(Input.GetKeyDown(KeyCode.R)){
- difference = 5 - currentClip;
- currentClip += difference;
- extraAmmo -= difference;
- }
- }
- }
- function shootUp(){
- if(Input.GetButtonDown("Fire1")){
- Instantiate(bulletObject, transform.position, Quaternion.identity);
- currentClip -= 1;
- }
- }
- function booleans(){
- if(extraAmmo <= 0){
- extraAmmo = 0;
- }
- if(extraAmmo > 0){
- canReload = true;
- }
- else{
- canReload = false;
- }
- if(extraAmmo <= 0){
- canReload = false;
- }
- if(currentClip < 5){
- canReload = true;
- }
- if(currentClip <= 0){
- canShoot = false;
- }else{
- canShoot = true;
- }
- if(canShoot == true){
- shootUp();
- }
- }
- function OnGUI(){
- GUI.Label(Rect(10,10,200,20),"" + currentClip);
- GUI.Label(Rect(18,10,200,20),"/" + extraAmmo);
- }
Advertisement
Add Comment
Please, Sign In to add comment