Game Development Reference
In-Depth Information
//Stop nav mesh agent movement
ThisAgent.Stop();
//Set up timer for attack interval
float ElapsedTime = 0f;
//Loop forever while in attack state
while(CurrentState == AI_ENEMY_STATE.ATTACK)
{
//Update timer
ElapsedTime += Time.deltaTime;
//Check if player has passed beyond the attack distance
if(!CanSeePlayer || Vector3.Distance(ThisTransform.position,
PlayerTransform.position) > DistEps)
{
//Change to chase
StartCoroutine(State_Chase());
yield break;
}
//Check attack delay
if(ElapsedTime >= AttackDelay)
{
//Reset counter
ElapsedTime = 0f;
//Launch attack
PlayerTransform.SendMessage("ChangeHealth",
-AttackDamage, SendMessageOptions.DontRequireReceiver);
}
//Wait until next frame
yield return null;
}
}
 
Search WWH ::




Custom Search