- Home /
How can i prevent player from flying
Im making this game where you have to jump thru levels like in mario but you have to swipe to move the player.
But my problem is that the player can constantly keep swiping to fly. i tried making a collider that checks if player is touching ground but that doesn't work because i still want player to be able to swipe one time in air (Like first swipe jump and second swipe move right or left in the air). Im pretty noob with coding so line of code would be helpful also.
(game is for android)
Answer by I_Am_Err00r · Jul 09, 2019 at 05:26 PM
In your movement script, it sounds like it handles the jump function as well.
What you need to do is create a public int of jumps and a private int of jumpsLeft, it looks something like this:
public class Example : Monobehaviour
{
public int numberOfJumps;
public void Start()
{
int numberOfJumpsLeft = numberOfJumps;
}
public void Update()
{
Jump();
}
public void Jump()
{
if (numberOfJumpsLeft = 0)
{
return;
}
if(Input.GetKeyDown.KeyCode(Space))
{
//Do the actual Jump itself
numberOfJumpsLeft --;
}
}
}
In that example make sure you set the number of jumps in the inspector, and the part that says "If (input...)" is just an example of when jump would be called; for you it would be something like if(firstSwipe)
Also, when you become grounded again, make sure you reset numberOfJumpsLeft back to numberOfJumps.
Your answer
Follow this Question
Related Questions
Swipe menu, problem! 0 Answers
Sliding Finger(touch) gesture? 1 Answer
Play animation on swipe (android) 1 Answer
How do i press multiple buttons at once in a single swipe 0 Answers
How to lock/hide android status bar/navigation bar? 0 Answers