Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have this running on the Update() on Unity. I am trying to create a page swipe feature on my game, but the problem is there is a half second delay when printing "dragging" to "end drag" when I release the mouse.

Does anyone have a method that will register input events faster?

void Update()
{
    if(isDragOn)
    {           
        if(Input.GetMouseButton(0))
        {
            print ("dragging");
            //moveContainers((Input.mousePosition.x - mouseLastPosition) * 0.01f);
            mouseLastPosition = Input.mousePosition.x;
        }
        else if(Input.GetMouseButtonUp(0))
        {
            print ("end drag");
            isDragMoved = false;
            isDragOn = false;
            endDrag();
        }
        else if(Input.touchCount > 0)
        {
            if(Input.GetTouch(0).phase == TouchPhase.Moved)
            {
                //moveContainers(Input.GetTouch(0).deltaPosition.x);
            }
            else if(Input.GetTouch(0).phase == TouchPhase.Ended)
            {
                isDragMoved = false;
                isDragOn = false;
                endDrag();
            }
        }
    }
}
share|improve this question
    
I tested your code on my machine, end drag is printed immediately when I release the mouse. I suggest you do some further debugging/optimization. –  Byte56 Aug 8 '13 at 3:35
    
I delete everything except for the print functions and it is still slow. Does that mean that my other code inside the script is affecting the update function? I always thought that how fast or slow update function is is based on what's inside this function. –  user1555300 Aug 8 '13 at 3:54
1  
Yes, that's true. But it's also affected by every other script's Update function. Every script on every object has an Update function, they all get run every frame. You may have too many objects, or one of your scripts has an Update function that takes a very long time to complete. –  Byte56 Aug 8 '13 at 3:57
    
cool. I'll check it out. –  user1555300 Aug 8 '13 at 3:58
    
I disabled the entire script and created a new script. I notice that when I tap, both button down and up register immediately. However, when I drag, there is a lag and button up doesn't always register. –  user1555300 Aug 8 '13 at 6:24

1 Answer 1

up vote 0 down vote accepted

There isn't going to be something "faster" than Update(reference), that runs once per frame:

Update is called every frame, if the MonoBehaviour is enabled.

If your frame rate is half a second per frame, then you'll get a half second delay. You'll need to perform some optimizations if you want faster response. Make sure your MonoBehaviour is enabled, and you're not running Update as part of a Coroutine. You can try creating a new project, and just putting your code into a new script on an otherwise empty object.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.