- Home /
Question by
sethi-sahil27 · Sep 18, 2016 at 02:38 PM ·
touchtouchphasetouch screen
Detect Long Press and single tap to make higher jumps
hi, i'm currently making a 2D endless runner, when the player taps on the screen once the object should jump a certain height say x, if the player long presses on the screen the object should jump again with a height say y (where y > x). this the code that i'm using , but it does'nt work for me.
Player.velocity = new Vector2 (PlayerVelx * Time.deltaTime,Player.velocity.y);
isGrounded = Physics2D.IsTouchingLayers (PlayerCollider,Ground);
if (Input.touchCount > 0)
{
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
if (isGrounded)
{
Press.text = "Short Jump ";
Player.velocity = new Vector2 (Player.velocity.x, PlayerVely * Time.deltaTime);
}
}
if (Input.GetTouch(0).phase == TouchPhase.Stationary )
{
if (isGrounded)
{
Press.text = "Long Jump ";
Player.velocity = new Vector2 (Player.velocity.x, PlayerVelyLong * Time.deltaTime);
}
}
}
Any help would be appreciated. thanks!
Comment
Your answer