x


Enemy fire script

Can anyone help me with a script to fire when the Player comes within range?

more ▼

asked Apr 13 '10 at 06:41 PM

Persona gravatar image

Persona
261 76 85 97

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Apr 13 '10 at 08:16 PM

duck gravatar image

duck ♦♦
41.4k 95 152 415

The only problem is that a bunch of bullets spray out instead 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);

}
Apr 16 '10 at 11:01 PM Persona
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x672
x286
x246
x153
x111

asked: Apr 13 '10 at 06:41 PM

Seen: 3355 times

Last Updated: Apr 13 '10 at 06:41 PM