- Home /
reading movement and screen buttons together on touch
I am having trouble "blocking" the movement of my player when I touch my pause and my unpause button. Is there a way to keep it from registering a touch on those two buttons or to make those buttons "dead zones" that dont read my touches.
Here's my movement method and the declared variables Movement() is called in the Update Method
Vector3 _myPosition;
private void Movement() { //overall movement method (time.timescale to maintain players speed throughout game) if (UIManager.uIManager.pauseMenuVisible == true) { transform.position = Vector3.Lerp(transform.position, _myPosition, _speed * Time.deltaTime);
}
else
{
transform.position = Vector3.Lerp(transform.position, _myPosition, _speed * Time.deltaTime * 1 / Time.timeScale);
}
if (Input.touchCount > 0)
{
Touch _touch = Input.GetTouch(0);
Vector3 _touchPosition = Camera.main.ScreenToWorldPoint(new Vector3(_touch.position.x, _touch.position.y, 10));
_myPosition = _touchPosition;
_animator.SetTrigger("Player_Run");
if (_myPosition.x >= 0f && _myPosition.x <= 3.5f && _myPosition.y >= -6f && _myPosition.y <= -1.2f)
{
_myPosition = new Vector3(1.74f, -2.4f, 0);
}
else if (_myPosition.x >= 0f && _myPosition.x <= 3.5f && _myPosition.y >= -1.21f && _myPosition.y <= 2f)
{
_myPosition = new Vector3(1.61f, .35f, 0);
}
else if (_myPosition.x >= 0f && _myPosition.x <= 3.5f && _myPosition.y >= 2.01f && _myPosition.y <= 6f)
{
_myPosition = new Vector3(1.52f, 3.9f, 0);
}
else if (_myPosition.x >= -3.5f && _myPosition.x <= -.01f && _myPosition.y >= -6f && _myPosition.y <= -1.2f)
{
_myPosition = new Vector3(-1.84f, -3.08f, 0);
}
else if (_myPosition.x >= -3.5f && _myPosition.x <= -.01f && _myPosition.y >= -1.21f && _myPosition.y <= 2f)
{
_myPosition = new Vector3(-1.77f, 1.04f, 0);
}
else if (_myPosition.x >= -3.5f && _myPosition.x <= -.01f && _myPosition.y >= 2.01f && _myPosition.y <= 6f)
{
_myPosition = new Vector3(-1.56f, 3.76f, 0);
}
}
}
NOTE - I am not having a problem with time.timeScale it works great. when i pause all motion stops. the problem is that when i hit the pause button before pause occurs the player will begin it's movement towards where that pause button is located and so on with the unPause button.
Your answer
Follow this Question
Related Questions
How do I move an object with my finger?[C#] 1 Answer
How to make basic touch screen controls 1 Answer
store the user touch input 0 Answers
Can't make cube follow the finger. 2 Answers