- Home /
How to make a character Jump given a certain condition
Hi. I am recently working on a project where i am creating a quiz game with a mix of a platform animation. I want to make my player jump when i answer correctly a question, but i don't know how to create a condition in C# in order to make him jump. Any ideas of how i can make it?
Answer by JooshDev · Feb 17, 2018 at 01:44 AM
Maybe put in a Boolean called canJump and have it set to false to start with. When an answer is current set it to true. Then in your player movement script have a condition where it can only jump if canJump is true. and after its jumped set it back to false if you want to limit them to only one jump, otherwise you could implement a counter to count the amount of jumps they can do.
Answer by Jasmin1347 · Feb 17, 2018 at 07:39 AM
bool answer = false;
Animator anim;
void Start()
{
answer = false;
anim = getComponent<Animator>():
}
void Update()
{
if (answer == true)
{
anim.setTrigger("jump");
}
}
apply this script to your player gameobject.
anim is an Animator component. That contain multiple animations. And "jump" is your animation name.
Animator must be attach to your player gameobject. setTrigger is parameter of your Animator. Here concentrate that your perimeter and state name of your animator must be same.
Where does "anim" come from, and if i include this code to my "Game $$anonymous$$anager" script how can i make a reference for the Jump trigger on my character control script?
Your answer
![](https://koobas.hobune.stream/wayback/20220612152803im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Inverted Char control 1 Answer
Controller Movement Problem 1 Answer
OnCollisionEnter Sine Wave to Character 0 Answers
2d Character runs in place via animator 0 Answers
The character controller stop moving when the Speed Start increase Endless runner 0 Answers