Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

how to make an enemy fire a bullet once every second

$
0
0
i have a very basic enemy AI script to make the enemy follow me and when within range shoot at me but it continuously fires bullets extremely fast. i want it to fire bullets much slower than it does. any way i can instantiate the bullet every second instead of constantly? my AI code is: var bullet : Transform; var bulletSpawn : Transform; function Update () { transform.LookAt(Player); if(Vector3.Distance(transform.position,Player.position) >= MinDist){ transform.position += transform.forward*MoveSpeed*Time.deltaTime; if(Vector3.Distance(transform.position,Player.position) <= MaxDist) { Instantiate(bullet, bulletSpawn.position, bulletSpawn.rotation); } } }

Viewing all articles
Browse latest Browse all 171066

Latest Images

Trending Articles



Latest Images

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