Esempio n. 1
0
    void Start()
    {
        // if player was not assigned in the inspector, take it from EnemyStatesAI instead
        if (player == null)
        {
            player = GetComponent <EnemyStatesAI> ().player.transform;
        }

        state           = GetComponent <EnemyStatesAI> ();
        crouchingScript = player.GetComponent <PlayerCrouchingScript> ();
        source          = GetComponent <AudioSource> ();
        source.clip     = sound;
    }
Esempio n. 2
0
 public void ToEngageStateNoSound()
 {
     enemy.navMeshAgent.speed *= 2f;
     enemy.currentState        = enemy.engageState;
     enemy.symbol.text         = "!";
     enemy.engageTarget        = enemy.player.transform;
     Collider[] otherEnemies = Physics.OverlapSphere(enemy.transform.position, enemy.alertRadius.radius);
     for (int i = 0; i < otherEnemies.Length; i++)
     {
         EnemyStatesAI AI = otherEnemies [i].gameObject.GetComponent <EnemyStatesAI> ();
         if (AI != null && AI.currentState != AI.engageState)               //checks if AI exists and its not already in engageState
         {
             otherEnemies[i].gameObject.GetComponent <EnemyStatesAI> ().currentState.ToEngageStateNoSound();
         }
     }
 }
Esempio n. 3
0
    public void ToEngageState()
    {
        enemy.navMeshAgent.speed *= 2f;
        enemy.currentState        = enemy.engageState;
        enemy.symbol.text         = "!";
        AudioSource.PlayClipAtPoint(enemy.seenSound, enemy.player.transform.position, 0.75f);
        enemy.engageTarget = enemy.player.transform;

        //gets array of nearby enemies and puts them in engage state as well
        Collider[] otherEnemies = Physics.OverlapSphere(enemy.transform.position, enemy.alertRadius.radius);
        for (int i = 0; i < otherEnemies.Length; i++)
        {
            EnemyStatesAI AI = otherEnemies [i].gameObject.GetComponent <EnemyStatesAI> ();
            if (AI != null && AI.currentState != AI.engageState)               //checks if AI exists and its not already in engageState
            {
                otherEnemies[i].gameObject.GetComponent <EnemyStatesAI> ().currentState.ToEngageStateNoSound();
            }
        }
    }
Esempio n. 4
0
    void Update()
    {
        if (Time.time > nextSpawnTime)
        {
            GameObject mob = Instantiate(mobToSpawn, transform.position, transform.rotation) as GameObject;

            //Gives the mob a reference to the player at creation time
            if (mob.GetComponent <EnemyStatesAI>() != null)
            {
                EnemyStatesAI mobAI = mob.GetComponent <EnemyStatesAI> ();
                mobAI.player       = refToPlayer;
                mobAI.engageTarget = refToPlayer.transform;
                mobAI.currentState.ToEngageStateNoSound();
            }


            nextSpawnTime = Time.time + spawnRate;
        }
    }
Esempio n. 5
0
 void Start()
 {
     enemy = GetComponentInParent <EnemyStatesAI> ();
 }
Esempio n. 6
0
 public EngageState(EnemyStatesAI e)
 {
     enemy    = e;
     isArcher = enemy.isArcher;
 }
Esempio n. 7
0
 public PatrolState(EnemyStatesAI e)
 {
     enemy = e;
 }
Esempio n. 8
0
 public AlertState(EnemyStatesAI e)
 {
     enemy = e;
 }