Exemple #1
0
    void Update()
    {
        if (enemy.inAction)
        {
            return;
        }

        else
        {
            flipTimer += Time.deltaTime;
            if (flipTimer >= flipCooldown)
            {
                enemy.LookAtTarget();
                flipTimer = 0;
            }

            int   dirX      = enemy.FacingRight ? 1 : -1;
            int   dirY      = enemy.PlayerDeltaY + 1.5 > 0 ? 1 : -1;
            float velocityX = dirX * speed;
            float velocityY = dirY * speed * 0.5f;

            if (this.WithinStopDistance())
            {
                velocityX = 0;
            }

            enemy.SetVelocityX(velocityX);
            enemy.SetVelocityY(velocityY);
        }
    }
    void attack()
    {
        if (enemy.inAction)
        {
            return;
        }

        enemy.inAction = true;
        enemy.SetVelocityX(0);
        enemy.SetVelocityY(0);
        enemy.Anim.SetTrigger("attack");
        StartCoroutine(WaitForAnimations("Attack", "Run"));
    }