Example #1
0
    protected void FixedUpdate()
    {
        switch (walkingState)
        {
        case MovingState.MOVING:
            if (Time.time - movingStateTimer >= movingTime)
            {
                walkingState     = MovingState.STAYING;
                movingStateTimer = Time.time;
                animActions.Stay();
            }
            else
            {
                agent.destination = player.componentCache.position;
            }
            break;

        case MovingState.STAYING:
            if (Time.time - movingStateTimer >= waitingTime)
            {
                if (touchingPlayer != null)
                {
                    if (touchingPlayer.TakeDamage(new DamageReport(damage * touchDamageMultiplier, this)))
                    {
                        touchingPlayer = null;
                    }
                    movingStateTimer = Time.time;
                    animActions.Stay();
                }
                else
                {
                    walkingState     = MovingState.MOVING;
                    movingStateTimer = Time.time + Random.Range(0, randomTime);
                    animActions.Run();
                }
            }
            else
            {
                agent.destination = transform.position;
                animActions.Stay();
            }
            break;

        default:
            break;
        }
    }
Example #2
0
    /// <summary>
    /// Called when Input Vector2 is changed
    /// </summary>
    /// <param name="direction"></param>
    private void CheckMovementState(Vector2 direction)
    {
        if (walkingState == MovingState.STAYING && direction != Vector2.zero)
        {
            walkingState = MovingState.MOVING;
            animActions.Run();
        }


        else
        {
            if (walkingState == MovingState.MOVING && direction == Vector2.zero)
            {
                walkingState = MovingState.STAYING;
                animActions.Stay();
                animActions.Attack();
            }
        }
    }