void FixedUpdate()
    {
        WeaponSystem weapon = base.GetComponent <WeaponSystem>();

        if (Input.GetKeyUp(KeyCode.Space))
        {
            weapon.Fire(WeaponSystem.WeaponType.Missile);
        }
    }
Exemple #2
0
    IEnumerator FirePlayerTwo()
    {
        playerTwoWeapon.Fire();
        playerTwoMovement.enabled = false;
        playerOneMovement.enabled = false;


        yield return(new WaitForSeconds(0.1f));
    }
Exemple #3
0
 public void Fire(GameTime gameTime, AmmoSystem ammoSystem)
 {
     if (frontWeapon.Fire() && ammoSystem.Usable())
     {
     }
     if (leftWeapon.Fire() && ammoSystem.Usable())
     {
     }
     if (rightWeapon.Fire() && ammoSystem.Usable())
     {
     }
 }
Exemple #4
0
    private void Update()
    {
        // TODO Input manager or smth
        // Movements
        var horizontal = Input.GetAxis("Horizontal") * Time.deltaTime * stats.speed;
        var vertical   = Input.GetAxis("Vertical") * Time.deltaTime * stats.speed;

        transform.Translate(new Vector3(horizontal, vertical), Space.World);

        transform.position = new Vector3(
            Mathf.Clamp(transform.position.x, border.xMin, border.xMax),
            Mathf.Clamp(transform.position.y, border.yMin, border.yMax),
            0f
            );

        // Firing
        if (weapsys.CanFire())
        {
            weapsys.Fire();
        }
    }
Exemple #5
0
    public override void FixedUpdate()
    {
        if (EnemyData == null)
        {
            return;
        }

        if (EnemyData.HasWeapon)
        {
            if (kDelay < 0f)
            {
                WeaponSystem weapon = base.GetComponent <WeaponSystem>();
                if (weapon != null)
                {
                    weapon.Fire(WeaponSystem.WeaponType.Missile);
                }
                kDelay = Random.Range(EnemyData.kWeaponMinWaitFire, EnemyData.kWeaponMaxWaitFire);
            }
            kDelay -= Time.fixedDeltaTime;
        }
        base.FixedUpdate();
    }
    // Update is called once per frame
    void Update()
    {
        if (CheckWeapon())
        {
            WeaponSystem weapon = GetCurWeapon();

            if (Controls.instance.GetFireDown())
            {
                canFire = true;
            }
            if (Controls.instance.GetFireUp())
            {
                canFire = false;
            }

            if (switching)
            {
                if (nextWeapon == curWeapon)
                {
                    weapon.transform.position         = Vector3.Lerp(defaultWeaponPos.position, defaultWeaponPos.position - Vector3.up * .2f, switchTimer / weapon.data.switchTime);
                    weapon.transform.localEulerAngles = Vector3.Lerp(defaultWeaponPos.localEulerAngles, defaultWeaponPos.localEulerAngles + Vector3.right * 30f, switchTimer / weapon.data.switchTime);

                    switchTimer -= Time.deltaTime;
                    if (switchTimer <= 0)
                    {
                        weapon.SwitchingWeapon(false);
                        switching = false;
                        weapon.transform.position         = defaultWeaponPos.position;
                        weapon.transform.localEulerAngles = defaultWeaponPos.localEulerAngles;

                        if (weapon.GetCurAmmo() == 0 && !weapon.IsReloading())
                        {
                            weapon.Reload();
                        }
                    }
                }
                else
                {
                    weapon.transform.position         = Vector3.Lerp(defaultWeaponPos.position - Vector3.up * .2f, defaultWeaponPos.position, switchTimer / weapon.data.switchTime);
                    weapon.transform.localEulerAngles = Vector3.Lerp(defaultWeaponPos.localEulerAngles + Vector3.right * 30f, defaultWeaponPos.localEulerAngles, switchTimer / weapon.data.switchTime);

                    switchTimer -= Time.deltaTime;
                    if (switchTimer <= 0)
                    {
                        weapon.SwitchingWeapon(false);
                        SetWeaponActive(weapon, false);

                        curWeapon = nextWeapon;
                        weapon    = GetCurWeapon();
                        weapon.SwitchingWeapon(true);
                        SetWeaponActive(weapon, true);
                        switchTimer = weapon.data.switchTime;

                        weapon.transform.position         = defaultWeaponPos.position - Vector3.up * .2f;
                        weapon.transform.localEulerAngles = defaultWeaponPos.localEulerAngles + Vector3.right * 30f;
                        LoadoutManager.instance.UpdateWeapon(weapon.GetCurAmmo(), weapon.data.ammo);
                    }
                }
            }
            else if (usingGrenade)
            {
                float scaledTimer = Mathf.Abs(throwGrenadeTimer - throwGrenadeTime * .5f) * 4f - throwGrenadeTime;
                weapon.transform.position         = Vector3.Lerp(defaultWeaponPos.position - Vector3.up * .1f, defaultWeaponPos.position, scaledTimer / throwGrenadeTime);
                weapon.transform.localEulerAngles = Vector3.Lerp(defaultWeaponPos.localEulerAngles + Vector3.right * 20f, defaultWeaponPos.localEulerAngles, scaledTimer / throwGrenadeTime);

                if (!grenadeThrown && throwGrenadeTimer < throwGrenadeTime - grenadeReleaseDelay)
                {
                    if (grenades.Length > activeGrenade && grenades[activeGrenade] != null)
                    {
                        Instantiate(grenades[activeGrenade], secondaryWeaponPos.position, secondaryWeaponPos.rotation);
                    }
                    grenadeThrown = true;
                }

                throwGrenadeTimer -= Time.deltaTime;

                if (throwGrenadeTimer <= 0)
                {
                    usingGrenade = false;
                }
            }
            else if (Controls.instance.GetGrenade())
            {
                ThrowGrenade();
            }
            else
            {
                Vector3 reticleCenter = Quaternion.AngleAxis(5, Camera.main.transform.right) * Camera.main.transform.forward;

                RaycastHit hit;
                if (Physics.Raycast(Camera.main.transform.position, reticleCenter, out hit, 100, ~0, QueryTriggerInteraction.Ignore))
                {
                    weapon.RotateWeapon(hit.point);
                }
                else
                {
                    weapon.RotateWeapon(weapon.transform.position + reticleCenter);
                }

                if (weapon.IsReloading() && reloadAnimTimer == -1)
                {
                    reloadAnimTimer = 0;
                }
                if (weapon.IsReloading() && reloadAnimTimer >= 0)
                {
                    weapon.transform.position         = Vector3.Lerp(defaultWeaponPos.position, defaultWeaponPos.position - Vector3.up * .1f, reloadAnimTimer / reloadAnimTime);
                    weapon.transform.localEulerAngles = Vector3.Lerp(defaultWeaponPos.localEulerAngles, defaultWeaponPos.localEulerAngles + Vector3.right * 20f, reloadAnimTimer / reloadAnimTime);
                    reloadAnimTimer = Mathf.Clamp(reloadAnimTimer + Time.deltaTime, 0, reloadAnimTime);
                }
                if (!weapon.IsReloading() && reloadAnimTimer >= 0)
                {
                    reloadAnimTimer = -1;
                }

                if (canFire)
                {
                    if (weapon.data.semiAuto && weapon.Ready())
                    {
                        canFire = false;
                    }
                    StartCoroutine(weapon.Fire());
                }
                if (Controls.instance.GetReload())
                {
                    weapon.Reload();
                }
                if (Controls.instance.GetSwitch())
                {
                    Switch(weapon, false);
                }
                else if (Controls.instance.GetSwitchToSidearm())
                {
                    Switch(weapon, true);
                }
            }
        }

        if (Controls.instance.GetInteractDown())
        {
            interacting = true;
        }

        if (interacting && Controls.instance.GetInteract())
        {
            Swap();
        }
        else
        {
            interactTimer = 0;
            interacting   = false;
        }

        int grenadeSwitch = Controls.instance.LeftRightArrow();

        if (!usingGrenade && grenadeSwitch != 0)
        {
            int looper = 0;
            do
            {
                activeGrenade = (activeGrenade + grenadeSwitch + activeGrenades.Length) % activeGrenades.Length;
            } while (!activeGrenades[activeGrenade] && looper++ < activeGrenades.Length);
            if (activeGrenades[activeGrenade])
            {
                HUDManager.instance.UpdateGrenadeSelection(activeGrenade);
            }
        }
    }