Hello I’m Leonardo, english is not my native language and I’m new to coding so i hope you will understand.
I’m trying to make my character jump when I hold the button and add a negative force on the y axis when i release.
I tried saying this:
if (Input.GetButton) { //if you hold the button
rigidbody2D.AddForce (new Vector2 (0, jumpForce));
}
if (Input.GetButtonUp) {
rigidbody2D.AddForce (new Vector2 (0, -jumpForce));
}
But the result was that the character goes up as long as i hold the button, but i want
it to go up and after 1 second (or less) to go down even if i hold the button for an infinite amount of time.
So my question is:
Can I add a force and after a while stop adding it? If not, what else can
I do to have the same effect?
Thanks in advance!
oh and forgot to say c# only