Exemple #1
0
 void UpdateAnimation()
 {
     if (CurrentState != _lastState)
     {
         ResetAllAnimation();
         an.SetBool(CurrentState.ToString(), true);
         _lastState = CurrentState;
     }
 }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        //CurrentState = StateSkeletonBoss.Attacking;
        if (CurrentState == StateSkeletonBoss.Walking || CurrentState == StateSkeletonBoss.Idle)
        {
            UpdateArrowCounter();
        }

        if (UpdateTimer(ref _deathCount))
        {
            Destroy(gameObject);
        }
        if (UpdateTimer(ref _attackCount))
        {
            CurrentState            = StateSkeletonBoss.Walking;
            _attackCooldownDuration = AttackCooldown;
        }

        UpdateTimer(ref _attackCooldownDuration);

        float hMov = 0;

        if (CurrentState == StateSkeletonBoss.Attacking && _attackCount <= SwordOnTime)
        {
            if (_attackCount <= SwordOffTime)
            {
                swordHitbox.enabled = false;
            }
            else
            {
                swordHitbox.enabled = true;
            }
        }

        if (CurrentState != StateSkeletonBoss.Attacking && _deathCount <= 0f)
        {
            float distance = Vector2.Distance(transform.position, playerTransform.position);
            if (distance < PlayerDistance)
            {
                if (distance < SkeletonAttackRange && _attackCooldownDuration <= 0f) // Attacks
                {
                    Attack();
                }
                else
                {
                    if (PlayerWithinArena()) // Walks Towards Player
                    {
                        CurrentState = StateSkeletonBoss.Walking;
                        hMov         = Mathf.Clamp(playerTransform.position.x - transform.position.x, -1, 1);
                        SetDirection(hMov.ToDirection());
                    }
                    else // Goes back to starting position
                    {
                        if (Vector2.Distance(transform.position, _startingPosition) < PositionError)
                        {
                            CurrentState = StateSkeletonBoss.Idle;
                            SetDirection(Mathf.Clamp(playerTransform.position.x - transform.position.x, -1, 1).ToDirection());
                        }
                        else
                        {
                            hMov = Mathf.Clamp(_startingPosition.x - transform.position.x, -1, 1);
                            SetDirection(hMov.ToDirection());
                            CurrentState = StateSkeletonBoss.Walking;
                        }
                    }
                }
            }
            else
            {
                CurrentState = StateSkeletonBoss.Idle;

                /*
                 * // Walk Routine
                 * Vector2 nextPosition = _patrolIndex == 0 ? ArenaLeft : ArenaRight;
                 *
                 * hMov = Mathf.Clamp(nextPosition.x - transform.position.x, -1, 1);
                 *
                 * if (Vector2.Distance(transform.position, nextPosition) < PositionError)
                 * {
                 *  _patrolIndex = _patrolIndex == 1 ? 0 : 1;
                 * }
                 *
                 * SetDirection(hMov.ToDirection());*/
            }
        }
        rb.velocity = new Vector2(hMov * Time.deltaTime * 60 * Speed, rb.velocity.y);

        UpdateAnimation();
    }
Exemple #3
0
 void Attack()
 {
     _attackCount = AttackDuration;
     CurrentState = StateSkeletonBoss.Attacking;
 }