Quantcast
Viewing all articles
Browse latest Browse all 1488

I am trying to make my enemy AI have an attack delay

right now my enemy AI attacks the player when in range but when it attacks it doesn't have a delay I've tried many different things to find an answer but none seem to work can someone help? My code given is being called by the void OnTriggerStay so it attacks each time the player is in the collider is there a way to add an attack delay to the enemies attack with the code i have given? void OnTriggerStay(Collider other) { if (other.gameObject == player) { Attack(); } } ' private void Attack() //Call this in OnTriggerStay if the colliding gameObject is the player { anim.SetTrigger("Attack"); //trigger our animation if (playerHealth.currentHealth > 0) { playerHealth.TakeDamage(attackDamage); //make player take damage } if (Time.time > attackDelay)//Check if current game time is at or past the time we last set { attackDelay = Time.time + attackRate; //Set timer to current game time plus our delay. } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>