예제 #1
0
 private void DoAttack()
 {
     if (canAttack)
     {
         canAttack = false;
         StartCoroutine(currentAttack.Attack(() => canAttack = true));
     }
 }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        hasReachDestination = aIPath.reachedEndOfPath;
        if (!hasReachDestination)
        {
            direction = aIPath.desiredVelocity;
        }

        if (state != State.Attack)
        {
            orientation();
            if (Time.time > timerTornado && !isLanchingTornado)
            {
                // lancer une tornade
                Debug.Log("prepare tornade");
                aIPath.canMove    = false;
                rb.velocity       = Vector2.zero;
                isLanchingTornado = true;
                anim.speed        = 2;
                state             = State.RangeAttack;
            }
            if (isLanchingTornado)
            {
                direction = new Vector2(playerPoisition.position.x - transform.position.x, playerPoisition.position.y - transform.position.y);
                orientation();
                anim.speed += tornadoLaunchSpeed * Time.deltaTime;
                if (anim.speed > tornadoLaunchTime)
                {
                    isLanchingTornado = false;
                    anim.speed        = 1;
                    aIPath.canMove    = true;
                    state             = State.Normal;
                    timerTornado      = Time.time + Random.Range(timeToNextTornadoMin, timeToNextTornadoMax);
                    Instantiate(tornadoPrefab, transform.position, Quaternion.identity);
                    attackState.nextAttackTime = Time.time + attackState.attackRate;
                    //Debug.Log("lance la tornade");
                }
            }
        }
        if (hasReachDestination && state != State.RangeAttack)
        {
            direction = new Vector2(playerPoisition.position.x - transform.position.x, playerPoisition.position.y - transform.position.y);
            if (state == State.Normal)
            {
                attackState.Attack();
            }
        }
    }
    protected void HandleAttackTimingOnUpdate()
    {
        if (attackManagementState == AttackManagementState.WAITING_FOR_ATTACK)
        {
            timeBetweenAttacksCounter -= Time.deltaTime;

            if (timeBetweenAttacksCounter <= 0)
            {
                ennemyCombatController.StopMovement();
                nextAttack.Attack();
            }
        }
        else if (attackManagementState == AttackManagementState.WAITING_FOR_DECISION)
        {
            ResetAttackTiming();
        }
    }