コード例 #1
0
    new void Start()
    {
        playerTransform = GameObject.FindGameObjectWithTag("Player").transform;

        var patrolState = new BasePatrolState(this);

        ChasePlayerStateModel chasePlayerStateModel = new ChasePlayerStateModel
        {
            playerTransform = playerTransform
        };
        var chasePlayerState = new ChasePlayerState(this, chasePlayerStateModel);

        AttackStateModel attackStateModel = new AttackStateModel
        {
            transform      = swordAttackPosition,
            range          = attackRange,
            delay          = attackDelay,
            damage         = attackDamage,
            onAttackStrike = onAttackStrike,
            attackSound    = attackSound
        };

        var attackState = new BaseAttackState(this, attackStateModel);

        stateMachine.AddTransition(patrolState, chasePlayerState, PlayerInAggroRange);
        stateMachine.AddAnyTransition(attackState, PlayerInAttackRange);
        stateMachine.AddAnyTransition(patrolState, () => !PlayerInAggroRange());
        stateMachine.AddTransition(attackState, chasePlayerState, () => !PlayerInAttackRange());

        stateMachine.SetState(patrolState);
    }
コード例 #2
0
    new void Start()
    {
        base.Start();

        var patrolState = new BasePatrolState(this);

        stateMachine.SetState(patrolState);
    }