- Home /
player jump on mousedown and swipe
hello,
My requirement is like this. Player should jump on mousedown. Player should jump on swipe up side. Player should come down on swipe down side.
The problem is that, when i swipe down side my mouse down code is executed and player jumps.
can anybody help me?
here is my code.
private void DetectTouch()
{
if (Input.GetMouseButtonDown(0))
{
Jump();
startPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
if (Input.GetMouseButton(0))
{
endPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition)
}
if (Input.GetMouseButtonUp(0) && !isJumping)
{
if ((startPosition.y - endPosition.y) < 0)
Jump();
else if (startPosition.y - endPosition.y > 0)
Down();
}
}
Comment
Input.Get$$anonymous$$ouseButtonUp(0) takes both mouse button and your very first touch.
Your answer
Follow this Question
Related Questions
Unity2D iOS Dragable items by touch 0 Answers
How do I apply a touch swipe code to be effective on all the screen? 1 Answer
Detect swipe along 3d arrows 1 Answer
swipe distance detection dont work 2 Answers
Help with swiping for movement 1 Answer