- Home /
Best Answer
Answer by duck · Apr 13, 2010 at 08:16 PM
Use a trigger volume. Set up a spherical trigger collider around your enemy (by adding a sphere collider, then checking "Is Trigger". Then use OnTriggerEnter handler in your enemy's script to call your enemy's Fire function.
If you haven't yet made a Fire function at all, you should probably either Instantiate a projectile prefab, and set its rotation and velocity using the player's forward direction, or cast a ray in the player's forward direction and apply damage to whatever it hits.
The only problem is that a bunch of bullets spray out ins$$anonymous$$d of one
if(disPlayer.magnitude < 7){
fire(); } } }
function fire() {
var BulletShot = Instantiate(Bullet, transform.position, transform.rotation);
BulletShot.rigidbody.AddForce(transform.forward * 1000);
yield WaitForSeconds(3);
}