- Home /
Question by
El-Deiablo · Jun 24, 2016 at 10:04 PM ·
player movementpausetouch controlspause menucancel
Cancel Touch on Pause
I am trying to cancel the player movement when the pause button is pressed. Currently when the user presses pause and scrolls through the options, the player moves along with the user's touch as well. I want to stop this. I tried out a few things, but have not been able to make it work.
Here's my code for player movement:
void Update(){
if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Moved) {
Vector2 touchDeltaPosition = Input.GetTouch (0).deltaPosition;
transform.Translate (touchDeltaPosition.x * speed, touchDeltaPosition.y * speed, 0);
//transform.Translate (touchDeltaPosition.x, touchDeltaPosition.y, 0);
if (PausePanel.isPaused == true) {
Input.GetTouch (0).phase == TouchPhase.Canceled;
transform.Translate (touchDeltaPosition.x * 0, touchDeltaPosition.y * 0, 0);
}
}
}
Comment
Best Answer
Answer by jgodfrey · Jun 24, 2016 at 10:17 PM
Assuming your "PausePanel.isPaused" property correctly contains your pause state, I'd think something like this would work:
void Update()
{
if (!PausePanel.IsPaused && Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Moved)
{
Vector2 touchDeltaPosition = Input.GetTouch (0).deltaPosition;
transform.Translate (touchDeltaPosition.x * speed, touchDeltaPosition.y * speed, 0);
}
}
So, essentially, just don't process the touch section of Update() if the IsPaused is set...
Your answer
![](https://koobas.hobune.stream/wayback/20220612083625im_/https://answers.unity.com/themes/thub/images/avi.jpg)