lock on enemy and shoot

Hi, Still having problems with working out this issue.

I want to be able to mouse down on a target, (lock on) then shoot until dead then mouse down on another target, (lock on) then shoot. You do it in almost every game.

mmmmmmmm.

Any assistace greatfully accepted.

The target object needs both a collider and a script on it that, on mouse down, sets a “current target” transform variable on your gun firing script to the target object’s transform component.

Then (as long as the target object still exists, is still in range, the gun still has enough bullets, and the mouse button is being held down,) the gun script needs to fire a bullet every n seconds toward the point where it will be if it continues on its current velocity for the time it takes a bullet to reach it.

If you have no clue how to turn any of that into script code, RTFM, and if still not, take a javascript programming class.