Weapon Firing Issue

I have a weapon that fires while stationary in iPhone. When I move my character I can no longer fire the weapon. When I am stationary again I can now fire the weapon again. Only when I move can I not fire the weapon. I am using the Penelope controls provided with iPhone. I have no issue with moving the player around, just firing while moving. Please help me. After some research I came up with this solution. It allows the weapon to fire while moving but when I press the move or rotate button it fires as well. Below is the code that I have added.

for (var evt : iPhoneTouch in iPhoneInput.touches){

if (evt.phase == iPhoneTouchPhase.Ended){   

    if (justLoaded) {
        startCannonWaitTime();
        justLoaded=false;

} else {

    FireProjectile();   

}

}

}

The above code will fire the cannon whenever you tap on the screen, move either rotate or forward/backward buttons. Now though when you place your fingers on either buttons the cannon will go off as well. So I have solved 1/2 my issue. Now how do I fix it so that the cannon will not fire when I first touch the buttons, it now works while I move them, but firing when first touching them is not good. Thank you for your patience with me.

I’m not sure that your code will fire on touching a button or whatever.This looks like your weapon will fire whenever you touch on anywhere on the screen rather than touching a particular button.To find that a particular object is touched or not you should try the following code.

`void FixedUpdate()

{
	if( Input.touchCount >= 1 )
	{
		Ray cursorRay = Camera.main.ScreenPointToRay(Input.GetTouch(0).position );
		RaycastHit hit;
		
		if( collider.Raycast( cursorRay, out hit, 1000.0f ) ) 
		{
                 //DoSomething
		}
		
	}

}

The above code detects whether an object is touched or not.If you want to fire when the user touches a particular button, its much more simpler.

void OnGUI () 
	{
		if (GUI.Button (new Rect (750,325, 120, 50),"Fire"))
						FireWeapon();


	}

The above code fires the weapon when the user touches the button named “Fire”.