Esempio n. 1
0
    void Update()
    {
        if (dwaft.currentHealth <= 0)
        {
            Destroy(gameObject);
        }

        if (!isAttack)
        {
            AnimationFollowEnemy(targetPosition);
            transform.position = Vector2.MoveTowards(transform.position, targetPosition,
                                                     speedMove * Time.deltaTime);
        }

        if (transform.position == targetPosition && !isIdle)
        {
            dwaft.AnimationIdle();
            isIdle = true;
        }

        if (enemyTransform != null)
        {
            Vector2 posAttack = new Vector2(enemyTransform.position.x,
                                            enemyTransform.position.y);

            if (Vector2.Distance(transform.position, enemyTransform.position) <= 0.8f)
            {
                dwaft.AnimationAttack();
            }
            else
            {
                AnimationFollowEnemy(posAttack);
                transform.position = Vector2.MoveTowards(transform.position, posAttack,
                                                         speedMove * Time.deltaTime);
            }

            isAttack = true;
        }
        else if (enemyTransform == null && isIdle)
        {
            checkLockTarget = false;
            isAttack        = false;
            dwaft.AnimationIdle();
        }
    }