Пример #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 MeleeAttackDelay(float delayTime)
    {
        yield return(new WaitForSeconds(delayTime));

        melee.Attack();
        view.animator.SetTrigger("Attack");
    }
Пример #3
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;
        }
    }
Пример #4
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         weapon.Attack();
     }
     return;
 }
Пример #5
0
 public void Attack()
 {
     if (allowAttack)
     {
         equippedWeapon.gameObject.SetActive(true);
         StartCoroutine(WeaponSwingAnimation());
         equippedWeapon.Attack();
     }
 }
Пример #6
0
    //0 = No side
    //1 = Left
    //2 = Right
    //3 = Dual

    public void Attack(int attackSide)
    {
        if (canAction)
        {
            if (attackSide == 1)
            {
                // Left Punch
                animator.SetTrigger("Attack" + (3).ToString() + "Trigger");
                leftPunch.Attack(stats.attackPower, attackDuration, attackDelay);
            }
            else
            {
                // Right Punch
                animator.SetTrigger("Attack" + (6).ToString() + "Trigger");
                leftPunch.Attack(stats.attackPower, attackDuration, attackDelay);
            }


            StartCoroutine(_LockMovementAndAttack(0, .6f));
        }
    }
Пример #7
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;
         }
     }
 }
Пример #8
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;
                }
            }
        }
    }
Пример #9
0
 public void _1_Attack_Must_Put_BoxCollider2D_Enabled_To_True()
 {
     target.Build(Vector2.one);
     target.Attack();
     Assert.IsTrue(target.areaOfEffect.enabled);
 }
Пример #10
0
    //0 = No side
    //1 = Left
    //2 = Right
    //3 = Dual

    public void Attack(int attackSide)
    {
        if (canAction)
        {
            // Lock on to nearby enemy
            // We can move this to a separate method
            Collider[] combatants = Physics.OverlapSphere(transform.position, lockOnRadius, combatantMask);
            if (combatants.Length > 0)
            {
                foreach (Collider combatant in combatants)
                {
                    Vector3 playerToCombatant = combatant.transform.position - transform.position;
                    playerToCombatant.y = 0f;
                    Quaternion rotationToCombatant = Quaternion.LookRotation(playerToCombatant);
                    if (Quaternion.Angle(transform.rotation, rotationToCombatant) < lockOnAngle)
                    {
                        transform.rotation = rotationToCombatant;
                        Debug.Log(gameObject.name + ": Locked onto " + combatant.name);
                        break;
                    }
                }
            }

            if (attackSide == 1)
            {
                // Left Punch
                animator.SetTrigger("Attack" + (3).ToString() + "Trigger");
                leftPunch.Attack(stats.attackPower, attackDuration, attackDelay);
            }
            else
            {
                // Right Punch
                animator.SetTrigger("Attack" + (6).ToString() + "Trigger");
                leftPunch.Attack(stats.attackPower, attackDuration, attackDelay);
            }


            StartCoroutine(_LockMovementAndAttack(0, .6f));

            //if (weapon == Weapon.UNARMED)
            //{
            //int maxAttacks = 3;
            //int attackNumber = 0;

            //if (attackSide == 1 || attackSide == 3)
            //{
            //    attackNumber = Random.Range(3, maxAttacks); // Left Hook
            //}
            //else if (attackSide == 2)
            //{
            //    attackNumber = Random.Range(6, maxAttacks + 3); // Right Hook
            //}
            //if (attackSide != 3)
            //{
            //    animator.SetTrigger("Attack" + (attackNumber).ToString() + "Trigger");

            //    StartCoroutine(_LockMovementAndAttack(0, .6f));
            //}
            //else
            //{
            //    // 2 Hand Attack
            //    animator.SetTrigger("AttackDual" + (attackNumber).ToString() + "Trigger");
            //    StartCoroutine(_LockMovementAndAttack(0, .75f));
            //}
            //}
            //else
            //{
            //    //  Armed Attack
            //    animator.SetTrigger("Attack" + (6).ToString() + "Trigger");
            //    StartCoroutine(_LockMovementAndAttack(0, .85f));
            //}
        }
    }
Пример #11
0
 void AttackMelee()
 {
     melee.Attack();
 }
Пример #12
0
    /*
     * void OnGUI(){
     *      GUI.Label (new Rect(50, Screen.height - 50, health, 50), healthbarTexture);
     *      GUI.Label (new Rect(200, Screen.height - 50, energy, 50), energybarTexture);
     * }
     */


    public void Attack(int type)
    {
        equippedWeapon.Attack(type);
    }
Пример #13
0
 public void MeleeAttack()
 {
     activeMeleeWeapon.Attack();
 }