コード例 #1
0
    public void UpdateState()
    {
        Movement player = statePatternEnemy.GetPlayer();

        if (player != null)
        {
            if (Vector2.Distance(statePatternEnemy.transform.position, statePatternEnemy.player.transform.position) < statePatternEnemy.minObserveDistance)
            {
                statePatternEnemy.ChangeState(new ChaseState(statePatternEnemy));
            }
        }
    }
コード例 #2
0
    public void UpdateState()
    {
        Movement player = statePatternEnemy.GetPlayer();

        if (player != null)
        {
            statePatternEnemy.movement.MoveTowardsObject(player);
            if (Vector2.Distance(statePatternEnemy.transform.position, statePatternEnemy.player.transform.position) < statePatternEnemy.maxAttackDistance && statePatternEnemy.CanSeePlayer() && (Time.time - statePatternEnemy.lastAttackTime > statePatternEnemy.timeBetweenAttacks))
            {
                statePatternEnemy.ChangeState(new AttackState(statePatternEnemy));
            }
            else if ((Time.time - statePatternEnemy.lastAttackTime > 2 * statePatternEnemy.timeBetweenAttacks))
            {
                statePatternEnemy.ChangeState(new AttackState(statePatternEnemy));
            }
        }
    }