unity3d - unity tap mobile issue -
i have simple scene when player taps, ball changes directions 90 degress; code works not perfect, issue "tap" detecting
needed use coroutine
make pause between taps, pause of 0.25sec
big , response time slow in cases, if try reduce pause time runs code fast no longer differ taps; i've tried touch.phase == began
, touch.phase.stationary
didn't work
i want achieve effect when tap, changes direction once, if hold it.
does have better solution of detecting taps?
using unityengine; using system.collections; public class playercontroller : monobehaviour { public float speed = 2f; public float tappausetime = .25f; rigidbody rb; bool timeron; bool goingright; void awake(){ rb = getcomponent<rigidbody> (); timeron = false; goingright = false; } // update called once per frame void update () { if (input.touchcount == 1 && !timeron && !goingright) { rb.velocity = vector3.zero; rb.angularvelocity = vector3.zero; rb.velocity = new vector3 (speed, 0, 0); timeron = true; goingright = true; startcoroutine(tappause()); } if(input.touchcount == 1 && !timeron && goingright) { rb.velocity = vector3.zero; rb.angularvelocity = vector3.zero; rb.velocity = new vector3(0,0,speed); timeron=true; goingright = false; startcoroutine(tappause()); } } ienumerator tappause(){ yield return new waitforseconds(tappausetime); timeron = false; }
}
if care single touch event (i.e. no multitouch), mouse handlers in input
mimic first touch. therefore, can use input.getmousebuttondown(0)
find out when there has been touch. fucntion return true frame mouse press (or in case, touch) occurs, , won't return true again until button has been released , pressed again. replace input.touchcount == 1
in if statements input.getmousebuttondown(0)
try this.
Comments
Post a Comment