Exemple #1
0
    protected override void CheckTransitions(FiniteStateMachine controller)
    {
        if (nextState == null)
        {
            nextState = GetComponent <PatrolState>();
        }

        if (playerSpotted)
        {
            ResetValues();
            AttackState state = GetComponent <AttackState>();
            state.StartAnimation();
            controller.TransitionToState(state);
            return;
        }

        // Check if finish idling
        if (idleTimer > maxIdleTime)
        {
            ResetValues();
            PatrolState state = GetComponent <PatrolState>();
            state.StartAnimation();
            controller.TransitionToState(state);
            return;
        }

        // Check if doll is nearby to trigger AttackState
        Transform target = controller.doll.transform;
        // Calculate direction
        Vector3 heading = target.position - controller.kid.transform.position;
        // if target reached, go to next waypoint
        float distance = heading.magnitude;

        if (distance < radiusTreshold)
        {
            ResetValues();
            AttackState state = GetComponent <AttackState>();
            state.StartAnimation();
            controller.TransitionToState(state);
            return;
        }
    }
    protected override void CheckTransitions(FiniteStateMachine controller)
    {
        // check if we should do a transistion
        if (playerSpotted)
        {
            ResetValues();
            AttackState state = GetComponent <AttackState>();
            state.StartAnimation();
            controller.TransitionToState(state);
            return;
        }

        if (shouldIdle)
        {
            ResetValues();
            audioSource.Stop();
            IdleState state = GetComponent <IdleState>();
            state.StartAnimation();
            controller.TransitionToState(state);
            return;
        }
    }