Advertisement
DesertOps

Weapon attack script

May 9th, 2017
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class WeaponAttack : MonoBehaviour {
  5.     GameObject bullet,curWeapon;
  6.     bool gun = false;
  7.     float timer = 0.1f, timerReset = 0.1f;
  8.     PlayerAnimate pa;
  9.     SpriteContainer sc;
  10.  
  11.     float weaponChange = 0.5f;
  12.     bool changingWeapon = false;
  13.  
  14.     // Use this for initialization
  15.     void Start () {
  16.         pa = this.GetComponent<PlayerAnimate> ();
  17.         sc = GameObject.FindGameObjectWithTag ("GameController").GetComponent<SpriteContainer> ();
  18.     }
  19.    
  20.     // Update is called once per frame
  21.     void Update () {
  22.         if (Input.GetMouseButton (0)) {
  23.             attack ();
  24.         }
  25.  
  26.         if (Input.GetMouseButtonDown (0)) {
  27.             pa.resetCounter ();
  28.         }
  29.  
  30.         if (Input.GetMouseButtonUp (0)) {
  31.             pa.resetCounter ();
  32.         }
  33.            
  34.         if (Input.GetMouseButtonDown (1) && changingWeapon == false) {
  35.             dropWeapon ();
  36.         }
  37.  
  38.         if (changingWeapon == true) {
  39.             weaponChange -= Time.deltaTime;
  40.             if (weaponChange <= 0) {
  41.                 changingWeapon = false;
  42.             }
  43.         }
  44.     }
  45.     public void setWeapon(GameObject cur, string name, float fireRate, bool gun)
  46.     {
  47.         changingWeapon = true;
  48.         curWeapon = cur;
  49.         pa.setNewTorso (sc.getWeaponWalk (name), sc.getWeapon (name));
  50.         this.gun = gun;
  51.         timerReset = fireRate;
  52.         timer = timerReset;
  53.     }
  54.     public void attack ()
  55.     {
  56.         pa.attack ();
  57.     }
  58.     public GameObject getCur()
  59.     {
  60.         return curWeapon;
  61.     }
  62.     public void dropWeapon ()
  63.     {
  64.         if (curWeapon != null) {
  65.             curWeapon.transform.position = this.transform.position;
  66.             curWeapon.SetActive (true);
  67.             setWeapon (null, "", 0.5f, false);
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement