コード例 #1
0
    private void Awake()
    {
        alertState    = new AlertState(this);
        coverState    = new CoverState(this);
        checkState    = new CheckState(this);
        engageState   = new EngageState(this);
        examineState  = new ExamineState(this);
        flankState    = new FlankState(this);
        patrolState   = new PatrolState(this);
        suppressState = new SuppressState(this);

        navMeshAgent = GetComponent <NavMeshAgent>();

        enemyHealth = GetComponent <EnemyHealth>();
    }
コード例 #2
0
 // Use this for initialization
 void Start()
 {
     if (PlayerPrefs.HasKey("HighScore"))
     {
         HighScore = PlayerPrefs.GetInt("HighScoreLevel" + levelLoaded);
     }
     else
     {
         HighScore = 0;
     }
     levelLoader = GetComponent <LevelLoader>();
     levelLoader.ReadAsset(levelTextAssets[levelLoaded]);
     chasestate = GetComponent <ChaseState>();
     flankstate = GetComponent <FlankState>();
     deathstate = GetComponent <DeathState>();
     system     = GetComponent <FSMSystem>();
 }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        if (moving)
        {
            switch (flankState)
            {
            case FlankState.flanking:
                // If the minimum time has passed
                if (OnTarget())
                {
                    // Set target and change state
                    flankState = FlankState.stopping;
                    SetTarget(transitionTime);
                }

                // Check if in flanking range
                if (minDistance <= PlayerDistance() && maxDistance >= PlayerDistance())
                {
                    // Stay still if within the range but the minimum flanking time hasn't passed yet
                    myBase.myRigid.velocity = Vector3.zero;
                }
                else if (minDistance > PlayerDistance())
                {
                    // Try to get more distance
                    MoveAway();
                }
                else
                {
                    // Try to get closer
                    MoveTowards();
                }
                break;

            case FlankState.stopping:
                // Transition to stationary at the appropriate time (without moving)
                myBase.myRigid.velocity = Vector3.zero;

                if (OnTarget())
                {
                    flankState = FlankState.stationary;
                    SetTarget(stationaryTime);
                }
                break;

            case FlankState.stationary:
                // Check if it should be on the next state (without moving)
                myBase.myRigid.velocity = Vector3.zero;

                if (OnTarget())
                {
                    flankState = FlankState.starting;
                    SetTarget(transitionTime);
                }
                break;

            case FlankState.starting:
                // Transition to stationary at the appropriate time (without moving)
                myBase.myRigid.velocity = Vector3.zero;

                if (OnTarget())
                {
                    flankState = FlankState.flanking;
                    SetTarget(movingTime);
                }
                break;
            }
        }
    }
コード例 #4
0
 public override void SetState(int newState)
 {
     this.flankState = (FlankState)newState;
 }