Holding down the left mouse to continually damage an ai?

This is my script, but the raycast only damages the ai every click, i want it to damage the ai even when i hold down the left mouse button:

function Update(){

if(Input.GetMouseButtonDown(0)){ // if the Left button pressed

// casts a ray from the mouse pointer

var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

var hit: RaycastHit;

if(Physics.Raycast(ray, hit)){ // if something hit, send the message

  hit.collider.SendMessageUpwards("ApplyDamage", 20, SendMessageOptions.DontRequireReceiver);




You want to use GetMouseButton rather than GetMouseButtonDown.

If you’re using C#, you need the out keyword before hit:
if(Physics.Raycast(ray, out hit))