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; }
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(); } } }
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(); } } }
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; } }
void Start() { enemy = GetComponentInParent <EnemyStatesAI> (); }
public EngageState(EnemyStatesAI e) { enemy = e; isArcher = enemy.isArcher; }
public PatrolState(EnemyStatesAI e) { enemy = e; }
public AlertState(EnemyStatesAI e) { enemy = e; }