示例#1
0
    private void UpdateState()
    {
        AbstractEnemyState newState = null;

        if (idleState.conditionsMet(this) && currentState.Name != idleState.Name)
        {
            newState = idleState;
        }

        if (patrolState.conditionsMet(this) && currentState.Name != patrolState.Name)
        {
            newState = patrolState;
        }

        if (chaseState.conditionsMet(this) && currentState.Name != chaseState.Name)
        {
            newState = chaseState;
        }

        if (attackState.conditionsMet(this) && currentState.Name != attackState.Name)
        {
            newState = attackState;
        }

        if (newState != null && newState != currentState)
        {
            newState.init();
            lastState    = currentState;
            currentState = newState;
        }
    }
示例#2
0
    private void UpdateState()
    {
        AbstractEnemyState newState = null;

        if (idleState.conditionsMet(this) && currentState.Name != idleState.Name)
        {
            newState = idleState;
        }

        if (patrolState.conditionsMet(this) && currentState.Name != patrolState.Name)
        {
            newState = patrolState;
        }

        if (runnerState.conditionsMet(this) && currentState.Name != runnerState.Name)
        {
            newState = runnerState;
        }

        if (summonerState.conditionsMet(this) && currentState.Name != summonerState.Name)
        {
            newState = summonerState;
        }


        if (newState != null && newState != currentState)
        {
            newState.init();
            lastState    = currentState;
            currentState = newState;
        }
    }
示例#3
0
    private void Update()
    {
        if (delayTime > 0)
        {
            // check if delayTime reached
            if (Time.timeSinceLevelLoad > delayTime)
            {
                delayTime      = 0;
                animator.speed = 1;
            }
        }
        else
        {
            // refresh AiBehaviour if not an interruptAction is finished
            if (aiBehaviour && aiBehaviour.enabled && !isInterruptAction)
            {
                currentAction = aiBehaviour.GetCurrentAction();
            }

            CheckForFalling();

            // handle StateMachine
            AbstractEnemyState newState = currentState.UpdateState();
            if (newState != null)
            {
                currentState.OnExit();
                currentState = newState;
                currentState.OnEnter();
            }
        }
    }
示例#4
0
 public void SetState(Type pState)
 {
     Debug.Log("Switching state to:" + pState.FullName);
     EnteredNewState = true;
     if (NavAgent.isOnNavMesh)
     {
         NavAgent.Stop();
     }
     SetSeeTarget();
     _state = _stateCache[pState];
 }
示例#5
0
    public virtual void Start()
    {
        defaultAction.moveTarget = Vector3.positiveInfinity;
        moveController           = GetComponent <IEnemyMoveController2D>();
        aiBehaviour    = GetComponent <AiBehaviour>();
        animator       = GetComponent <Animator>();
        spriteRenderer = GetComponent <SpriteRenderer>();
        hitBox         = GetComponentInChildren <HitBox>();

        if (aiBehaviour && aiBehaviour.enabled)
        {
            aiBehaviour.defaultAction = defaultAction;
            currentAction             = aiBehaviour.GetCurrentAction();
        }
        else
        {
            currentAction = defaultAction;
        }

        boxCollider = GetComponent <BoxCollider2D>();

        hurtBox = GetComponent <HurtBox>();
        if (!hurtBox)
        {
            // search in children
            hurtBox = transform.GetComponentInChildren <HurtBox>();
        }

        // init ENEMY state
        currentState = new EnemyIdleState(this);

        if (randomDelaySeconds > 0)
        {
            delayTime      = Random.Range(0F, randomDelaySeconds);
            animator.speed = 0;
        }
    }