Exemple #1
0
        //function call to fire the weapon
        public void Fire()
        {
            currentCD = GetCoolDown();
            recoil   += GetRecoilMagnitude() * 2;

            AudioManager.PlaySound(shootSFX);

            //for weapon with finite clip
            if (currentClip > 0)
            {
                currentClip -= 1;
                if (currentClip <= 0)                   //if out of ammo
                //if this is a temporary weapon, remove the weapon
                {
                    if (temporary)
                    {
                        GameControl.GetPlayer().RemoveWeapon();
                        return;
                    }

                    //if auto reload is enabled, reload
                    if (GameControl.EnableAutoReload())
                    {
                        Reload();
                    }
                }
            }
        }
Exemple #2
0
        public void SwitchWeapon(int newID)
        {
            weaponList[weaponID].gameObject.SetActive(false);
            weaponList[newID].gameObject.SetActive(true);

            if (weaponList[newID].currentClip == 0 && GameControl.EnableAutoReload())
            {
                weaponList[newID].Reload();
            }

            TDS.SwitchWeapon(weaponList[newID]);

            weaponID = newID;
        }
Exemple #3
0
        //fire main weapon
        public void FireWeapon()
        {
            if (destroyed || IsStunned())
            {
                return;
            }
            if (!thisObj.activeInHierarchy)
            {
                return;
            }

            int fireState = CanFire();

            if (fireState == 0)
            {
                if (weaponList[weaponID].RequireAiming())
                {
                    Vector2 cursorPos = Input.mousePosition;

                    if (weaponList[weaponID].RandCursorForRecoil())
                    {
                        float recoil = GameControl.GetPlayer().GetRecoil() * 4;
                        cursorPos += new Vector2(Random.value - 0.5f, Random.value - 0.5f) * recoil;
                    }

                    Ray        ray = Camera.main.ScreenPointToRay(cursorPos);
                    RaycastHit hit;
                    //LayerMask mask=1<<TDS.GetLayerTerrain();
                    //Physics.Raycast(ray, out hit, Mathf.Infinity, mask);
                    Physics.Raycast(ray, out hit, Mathf.Infinity);

                    ShootObject.AimInfo aimInfo = new ShootObject.AimInfo(hit);

                    StartCoroutine(ShootRoutine(aimInfo));
                }
                else
                {
                    StartCoroutine(ShootRoutine());
                }

                weaponList[weaponID].Fire();
            }
            else
            {
                string text = "";
                if (fireState == 1)
                {
                    text = "attack disabled";
                }
                if (fireState == 2)
                {
                    text = "weapon's on cooldown";
                }
                if (fireState == 3)
                {
                    text = "weapon's out of ammo";
                }
                if (fireState == 4)
                {
                    text = "weapon's reloading";
                }
                TDS.FireFail(text);

                if (GetCurrentClip() == 0 && GameControl.EnableAutoReload())
                {
                    weaponList[weaponID].Reload();
                }
            }
        }