I'm trying to create iPhone button that would continuously Instantiate bullets when finger touches this button and is held down, without conflicting with other buttons, for example, rotation joystick. At the moment I have this code that sends only one Message each time when button gets touched ( I also have script from 3rd Person Camera Prefab, which sends message when finger is RELEASED, but that one is much longer and more complicated). Maybe somebody has an idea how to keep sending message to target for few times per second untill finger is released from button...
Thanks in advance!
var recoveryTime = 10;
private var delay = 0;
var target : MonoBehaviour; //Target of the message to be sent
var message : String ; //Message to be sent
function Update () {
if (delay>0){delay -=1;}
if (delay==0){
if(iPhoneInput.touchCount == 1){
var currentTouch:iPhoneTouch = iPhoneInput.touches[0];
if(currentTouch.phase == iPhoneTouchPhase.Began && guiTexture.HitTest(currentTouch.position)){
target.Invoke(message, 0);
delay = recoveryTime;
}
}
}
}