- Home /
How can I make my offset stay for a certain amount of time?
I was just wondering how I can put a time limit on this offset so it stays at this offset until the set time is up if this is even possible, I am new to coding in c# and unity so any help would be appreciated. Thanks
public void Jump()
{
if (Input.GetKeyDown(KeyCode.Space) | (Input.GetKeyUp(KeyCode.Space)))
{
IsJumping = !IsJumping;
if (IsJumping)
{
rhRegularOffset = rhJumpingOffset;
}
else
{
rhRegularOffset = noAimRhRegularOffset;
}
}
}
Comment
Best Answer
Answer by badadam · Mar 08, 2019 at 07:28 PM
You can use the script below
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (IsJumping == false)
{
IsJumping = true;
rhRegularOffset = rhJumpingOffset;
Invoke("resetOffset", timeWaiting);
}
}
}
public void resetOffset()
{
rhRegularOffset = noAimRhRegularOffset;
IsJumping = false;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612193220im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Frame dependant timer 1 Answer