예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (enemyController.freezeEnemy)
        {
            // add anything here to happen while frozen i.e. time compensations
            return;
        }

        // do ScrewDriver ai logic if it's enabled
        if (enableAI)
        {
            // get player position
            if (player != null)
            {
                playerPosition = player.transform.position;
            }

            // screwdriver has only two states - closed and open
            // while closed he's below standing megaman's bullet height
            // while open he shoots bullet spreads two times
            switch (screwDriverState)
            {
            case ScrewDriverState.Closed:
                animator.Play("ScrewDriver_Closed");
                // check distance to player
                if (player != null && !doAttack)
                {
                    float distance = Vector2.Distance(transform.position, playerPosition);
                    if (distance <= playerRange)
                    {
                        doAttack  = true;
                        openTimer = openDelay;
                    }
                }
                // within distance and can attack
                if (doAttack)
                {
                    // delay before opening to attack
                    openTimer -= Time.deltaTime;
                    if (openTimer <= 0)
                    {
                        // switch to open state
                        // NOTE: animation has events that shoot the bullets and goes back to closed state
                        screwDriverState = ScrewDriverState.Open;
                    }
                }
                break;

            case ScrewDriverState.Open:
                // firing of the bullets is performed via animation events calling ShootBullet()
                animator.Play("ScrewDriver_Open");
                break;
            }
        }
    }
예제 #2
0
 // called from the last animation event in the ScrewDriver_Open animation
 private void OpenAnimationStop()
 {
     doAttack         = false;
     screwDriverState = ScrewDriverState.Closed;
 }