Unity 2019 - Resume Button is interacting with my jump rigidbody (Touchscreen Input) - How to fix?
Hello guys.
I have this simple code. I have used the if statement to check that if i press the pause button, the jump animation will not be triggered. After the Paused Menu is activated, when i click resume, the game will start immediately and the character will jump straight away. I have tried using Coroutines, with real time and time.timeScale = 0.001, but the action will still be triggered. Any ideas on how to solve?
// -> Player part of the code
private void Jump()
{
if (Input.touchCount > 0 && rb.velocity.y == 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
startTouchPosition = Input.GetTouch(0).position;
if (startTouchPosition.x < screenMinusButton.x || startTouchPosition.y < screenMinusButton.y)
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
}
// -> Another part of the code
public void ResumeButton()
{
pausePanel.SetActive(false);
GameIsPaused = false;
StartCoroutine(Pause(0.2f));
}
private IEnumerator Pause(float p)
{
//Time.timeScale = 0.1f;
float pauseEndTime = Time.realtimeSinceStartup + p;
while (Time.realtimeSinceStartup < pauseEndTime)
{
yield return 0;
}
Time.timeScale = 1;
}
Your answer
Follow this Question
Related Questions
Ui Collision Detection 0 Answers
Do I have to add RigidBody2D to a moving UI? 0 Answers
With the new unity input system. How do I setup UI buttons like in the old system. 0 Answers
can't detect touch on screen 0 Answers
[HELP] 2D Ammo UI error wont count down shooting count and wont pick up and change ammo count 0 Answers