// Use this for initialization void Start() { playerhealth = player.GetComponent <PlayerHealth>(); gun = guntest.GetComponent <Gun>(); ammo1 = weapons[0].GetComponent <AMMOTEST>(); ammo2 = weapons[1].GetComponent <AMMOTEST>(); ammo3 = weapons[2].GetComponent <AMMOTEST>(); buffer = 1; SelectWeapon(1); }
// Update is called once per frame //Shoot and play particle effects on click void Update() { guntest = GameObject.FindGameObjectWithTag("Gun"); test = guntest.GetComponent <AMMOTEST>(); timer += Time.deltaTime; gunParticles = GetComponentInChildren <ParticleSystem>(); if (Input.GetButtonDown("Fire1") && reloading != true && timer >= weapons[currentWeapon].timeBetweenBullets && swap != true && test.currentAmmo > 0 && currentWeapon == 0 && pistollock == true) { if (test.currentAmmo > 0) { Shoot(); anim.SetTrigger("shoot_pistol"); } if (test.currentAmmo == 0) { Reload(); } } if (Input.GetButton("Fire1") && reloading != true && timer >= weapons[currentWeapon].timeBetweenBullets && swap != true && test.currentAmmo > 0 && currentWeapon == 1) { if (test.currentAmmo > 0) { Shoot(); anim.SetTrigger("uzi_shoot"); } if (test.currentAmmo == 0) { Reload(); } } if (Input.GetButton("Fire1") && reloading != true && timer >= weapons[currentWeapon].timeBetweenBullets && swap != true && test.currentAmmo > 0 && currentWeapon == 2 && riflelock == true) { if (test.currentAmmo > 0) { Shoot(); anim.SetTrigger("rifle_shoot"); } if (test.currentAmmo == 0) { Reload(); } } if (timer >= weapons[currentWeapon].timeBetweenBullets * effectsDisplayTime) { DisableEffects(); } if (Input.GetButtonDown("Reload") && test.currentAmmo != weapons[currentWeapon].maxClip) { Reload(); } if (reloading != true && Input.GetButtonDown("Primary Weapon") && pistollock == true && currentWeapon != 0) { myAudioSource.Stop(); StartCoroutine(Swap()); currentWeapon = 0; } if (reloading != true && Input.GetButtonDown("Secondary Weapon") && currentWeapon != 1) { myAudioSource.Stop(); StartCoroutine(Swap()); currentWeapon = 1; } if (reloading != true && Input.GetKeyDown(KeyCode.Alpha3) && riflelock == true && currentWeapon != 2) { myAudioSource.Stop(); StartCoroutine(Swap()); currentWeapon = 2; } Debug.Log(currentWeapon); text.text = test.currentAmmo + " / " + test.totalAmmo; }