コード例 #1
0
    void Update()
    {
        //If the boss is not dead,
        if (!isDead)
        {
            //If the boss is in combat,
            if (inCombat)
            {
                //If the boss is close enough to the player,
                if (Vector3.Distance(transform.position, player.transform.position) <= attackDistance)
                {
                    //If the boss is not attacking and it is time to attack,
                    if (isAttacking == false && attackTimer >= attackTime)
                    {
                        //Attack animation and indicate attack
                        animator.SetBool("isAttacking", true);
                        isAttacking = true;
                        attackTimer = 0;
                    }
                    else
                    {
                        //If a second has passed since the attack,
                        if (attackTimer > 1)
                        {
                            //Stop animation and indicate attack over
                            animator.SetBool("isAttacking", false);
                            isAttacking = false;
                        }
                    }
                }
                else
                {
                    //Stop animation and indicate attack over
                    animator.SetBool("isAttacking", false);
                    isAttacking = false;
                }
            }

            //If boss attacking,
            if (animator.GetCurrentAnimatorStateInfo(0).IsName("mutant_Punching"))
            {
                //Activate weapon's collider
                weapon.GetComponent <BoxCollider>().enabled = true;
            }
            else
            {
                weapon.GetComponent <BoxCollider>().enabled = false;
            }
        }
        //If the boss is out of combat,
        else
        {
            //Reduce weapon's power
            weapon.power = 0;
        }
    }
コード例 #2
0
    // This is called once per update
    public override void MovePattern () {
        // print (playerFound);
        if (playerFound) {
            rb.velocity = new Vector2 (0f, rb.velocity.y);
            GetComponent<SpriteRenderer> ().flipX = false;
            GetComponent<Animator> ().SetBool ("moving", false);
            weapon.GetComponent<SpriteRenderer> ().enabled = true;
            arm.LookAt (player.transform);
            // weapon.GetComponent<SpriteRenderer> ().flipY = ((player.transform.position.x - transform.position.x) < 0);
        } else {
            GetComponent<Animator> ().SetBool ("moving", true);
            GetComponent<SpriteRenderer> ().flipX = true;
            weapon.GetComponent<SpriteRenderer> ().enabled = false;
            if (Vector2.Distance (player.transform.position, transform.position) < detectRange)
                rb.AddForce (Vector3.Normalize ((Vector2) (player.transform.position - transform.position)) * speed);
            // print (Vector3.Normalize ((Vector2) (player.transform.position - transform.position)) * speed);
            if (movingRight) {
                if (!facingRight) {
                    Flip ();
                }
            }

            if (rb.position.x >= endPos) {
                movingRight = false;
            }

            if (!movingRight) {
                if (facingRight) {
                    Flip ();
                }
            }

            if (rb.position.x <= startPos) {
                movingRight = true;
            }
        }
        base.MovePattern();
    }
コード例 #3
0
ファイル: Faded.cs プロジェクト: jgalecki/Caravana
 private void AttackTarget()
 {
     if (_attackTimer <= 0)
     {
         Animator.SetBool("IsAttacking", true);
         _attackTimer  = AttackCooldown;
         Weapon.Active = false;
     }
     else if (_attackTimer <= AttackCooldown - AttackDuration)
     {
         Weapon.Active    = false;
         Weapon.WeaponHit = false;
     }
     else if (_attackTimer < AttackCooldown - HitBoxDelay && !Weapon.WeaponHit)
     {
         Weapon.Active = true;
         Weapon.GetComponent <Collider2D>().offset = new Vector2(_faceLeft ? WEAPON_X_OFFSET_LEFT : WEAPON_X_OFFSET_RIGHT, WEAPON_Y_OFFSET);
     }
 }