Пример #1
0
        /// <summary>
        /// Attempts use the current weapon to attack/fire
        /// </summary>
        /// <returns>bool: true, if the attempted attack was successful(bullets fired for ranged weapons)</returns>
        public bool Attack()
        {
            if (_weapon.Properties.weaponGroup == WeaponGroup.Main ||
                _weapon.Properties.weaponGroup == WeaponGroup.Secondary)
            {
                RangedWeapon weapon = _weapon as RangedWeapon;

                if (weapon.CurrentAmmo == 0)
                {
                    weapon.Attack(CurrentSpread, true);
                    return(false);
                }

                else
                {
                    weapon.Attack(CurrentSpread, false);
                    _currentSpread += weapon.SpreadStep;

                    if (OnWeaponAttack != null)
                    {
                        OnWeaponAttack.Invoke();
                    }

                    return(true);
                }
            }

            else
            {
                MeleeWeapon weapon = _weapon as MeleeWeapon;
                weapon.Attack();
                return(true);
            }
        }
Пример #2
0
    IEnumerator RangedAttackDelay(float delayTime)
    {
        yield return(new WaitForSeconds(delayTime));

        ranged.Attack(model.rangedAttackPattern.ToString());
        view.animator.SetTrigger("Attack");
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            if (gun != null)
            {
                gun.Attack();
            }
            if (gun2 != null)
            {
                gun2.Attack();
            }
        }

        //临时代码
        if (Input.GetKeyDown(KeyCode.R))
        {
            if (gun != null)
            {
                gun.newReload();
            }
            if (gun2 != null)
            {
                gun2.newReload();
            }
        }
    }
Пример #4
0
    //TODO: do not run this if inventor is open
    public void Attack()
    {
        if (animator.GetBool("Melee") == true)
        {
            meleeInUse  = true;
            rangedInUse = false;
        }
        else
        {
            rangedInUse = true;
            meleeInUse  = false;
        }

        if (Input.GetMouseButtonDown(0) && meleeInUse && currentMeleeWeapon != null && !inventoryPanel.GetComponent <Transform>().parent.transform.gameObject.activeSelf)
        {
            SetOrientation();
            Debug.Log(orientation);
            currentMeleeWeapon.Attack();
        }
        else if (Input.GetMouseButton(0) && rangedInUse && currentRangedWeapon != null && !inventoryPanel.GetComponent <Transform>().parent.transform.gameObject.activeSelf)
        {
            SetOrientation();
            holdTimeDelta += Time.deltaTime;
        }
        //launching arrow
        if (Input.GetMouseButtonUp(0) && rangedInUse && currentRangedWeapon != null && !inventoryPanel.GetComponent <Transform>().parent.transform.gameObject.activeSelf)

        {
            currentRangedWeapon.Attack();
            holdTimeDelta = 0;
        }
    }
Пример #5
0
 void Update()
 {
     //If attack has reset to avoid attack spamming
     if (Time.time >= nextAttackTime)
     {
         if (Input.GetKeyDown(KeyCode.Mouse0))
         {
             animator.SetTrigger("Attack");
             melee.Attack();
             nextAttackTime = Time.time + 1f / meleeAttackRate;
         }
         else if (Input.GetKeyDown(KeyCode.Mouse1))
         {
             ranged.Attack("Default");
             nextAttackTime = Time.time + 1f / shootAttackRate;
         }
     }
 }
Пример #6
0
    void Update()
    {
        if (PauseMenuController.GameIsPaused == false && view.animator != null)
        {
            model.newPosition = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
            CheckForDoors();

            // Check if player should be dead
            if (model.health <= 0.0f)
            {
                FindObjectOfType <AudioManager>().Play("Player Dead");
                playerHealthScript.UpdateHealth();
                playerHealthScript.InitiateGameOver();
                view.SetDead(true);
                gameOverMenu.EnableGameOver();
                model.rigidBody.velocity = new Vector3(0, 0, 0); // Stop player movement

                // Disable MVC
                model.enabled = false;
                view.enabled  = false;
                this.enabled  = false;
            }

            HealthPickup();

            if (Time.time >= model.nextAttackTime)
            {
                if (Input.GetKey(KeyCode.Mouse0))
                {
                    FindObjectOfType <AudioManager>().Play("Melee");
                    view.swordAnimator.SetTrigger("Attack");
                    meleeWeaponScript.Attack();
                    model.nextAttackTime = Time.time + 1f / model.meleeAttackRate;
                }
                else if (Input.GetKey(KeyCode.Mouse1))
                {
                    FindObjectOfType <AudioManager>().Play("Shoot");
                    rangedWeaponScript.Attack(model.rangedAttackPattern.ToString());
                    model.nextAttackTime = Time.time + 1f / model.rangedAttackRate;
                }
            }
        }
    }