Exemplo n.º 1
0
 private void LoadAIState(bool isBrutus)
 {
     if (isBrutus)
     {
         if (isBrutusResponder)
         {
             brutusResponderStates = Utils.GetRequiredComponent <BrutusResponder>(this);
             brutusResponderStates.chaser.OnSeePlayer          += TargetSpottedBark;
             brutusResponderStates.chaser.OnLosePlayer         += TargetLostBark;
             brutusResponderStates.responder.OnStartResponding += ReactiveBark;
         }
         else
         {
             brutusStates = Utils.GetRequiredComponent <AIBrutusOffice>(this);
             brutusStates.chaser.OnSeePlayer          += TargetSpottedBark;
             brutusStates.chaser.OnLosePlayer         += TargetLostBark;
             brutusStates.responder.OnStartResponding += ReactiveBark;
         }
     }
     else
     {
         basicNurseStates = Utils.GetRequiredComponent <BasicNurse>(this);
         basicNurseStates.chaser.OnSeePlayer          += TargetSpottedBark;
         basicNurseStates.chaser.OnLosePlayer         += TargetLostBark;
         basicNurseStates.responder.OnStartResponding += ReactiveBark;
     }
 }
Exemplo n.º 2
0
    public List <BasicNurse> SpawnEnemyNurses(List <MissionEnemy> enemies, System.Action onCollideAction)
    {
        List <BasicNurse> instantiatedEnemies = new List <BasicNurse>();

        // Instantiate all enemies
        enemies.ForEach(enemy =>
        {
            // We can only spawn a NavMeshAgent on a position close enough to a NavMesh, so we must sample the inputted position first just in case.
            if (NavMesh.SamplePosition(enemy.spawnPosition, out NavMeshHit closestNavmeshHit, 10.0f, NavMesh.AllAreas))
            {
                GameObject spawnedEnemy = Instantiate(enemy.prefab, closestNavmeshHit.position, Quaternion.Euler(enemy.spawnRotation));

                // All enemies will be chasers, so we need to set the target transform for all.
                BasicNurse enemyComponent = Utils.GetRequiredComponent <BasicNurse>(spawnedEnemy, $"Enemy does not have a BasicNurse component!");
                enemyComponent.enemy.OnCollideWithPlayer += onCollideAction;

                enemyComponent.patroller.SetPoints(enemy.waypoints);
                if (enemy.isInitiallyResponding)
                {
                    enemyComponent.responder.InitializeResponderParameters(enemy.startResponsePoint);
                }

                instantiatedEnemies.Add(enemyComponent);
            }