TouchPhase.Ended does not work if ray is not hitting object.

I am using a raycast to detect if a player is touching an object. When the player touches the object, it fires. Firing works great, however it seems as if the player releases the finger anywhere other than right on top of the object where the ray hits, it does not recognize that the player let go, and continues to fire. What would be a better way to approach this?

var myTouches:Touch[] = Input.touches;
for(var i:int=0;i<Input.touchCount;i++)
{
 var hit : RaycastHit;
 var ray = Camera.main.ScreenPointToRay (myTouches*.position);* 

if (Physics.Raycast (ray, hit, 1000))
{

if(hit.collider.gameObject.tag == “handle”)
{
var tower = hit.collider.transform.parent.gameObject.GetComponent(TowerController);

if (myTouches*.phase == TouchPhase.Began)*
{
tower.firing=true;
tower.handlefree=false;
}

if (myTouches*.phase == TouchPhase.Ended)*
{
tower.firing=false;
tower.handlefree=true;
}
}

I would test that the touch with the same finger id still exists, and isn’t Ended or Cancelled. Unity prioritises framerate over input and can lose touch events especially if the frame rate drops - you can modify the Xcode project to alter that behaviour but you are probably better off not expecting every phase as I suggest at the start of this answer.