- Home /
Problems with Touch Screen and Pause Game?
Hello everyone.I'm having problem.I'm making a 2d platform game.My character will jump when I touch finger on screen mobile android. But when i click on pause button of NGUI then character aslo jump and dialog pause appear .I think because touch screen's still running . Now i want to character can't jump when click on pause button that only jump when click on touch screen..how to disable touch screen before click on pause button because it always occur before when click pause button.Please help me.Thank you very much.
first thing i want to say thank you.this is my code: Class TouchScreen attached on Scene
PlayerControl player;
void Start () {
player = GameObject.Find("Player").GetComponent<PlayerControl>();
}
void Update()
{
if (Input.Get$$anonymous$$ouseButtonDown(0))
{
player.UpdateJumpHandler(); //reference to UpdateJumpHandler function to Jump when touch on screen.
}
//else
//{
// GameControler.buttonPressed = false;
//}
}
Then I have a PauseScript class attached on Camera :
public void PauseGame()
{
if (!isPaused )
{
// Debug.Log("Paused");
Time.timeScale = 0.0f;
isPaused = true;
// player.enabled = !player.enabled;
// EasyTouch.SetEnabled(false);
// player.jumpPower = 0;
// pausePlayer.collider.enabled = false;
}
//foreach (GameObject game in gameTag)
//{
// game.gameObject.collider.enabled = false;
//}
}
public void ResumeGame()
{
if (isPaused)
{
// Debug.Log("Unpaused");
Time.timeScale = 1.0f;
isPaused = false;
//player.jumpPower = 500f;
}
I created a button by NGUI called it is Pause and attached a GameControler class :
public void ButtonPause()
{
// players.jumpPower = 0;
pause.PauseGame();
buttonPressed = true;
// players.enabled = !players.enabled;
// touch.enabled = !touch.enabled;
// EasyTouch.SetEnabled(false);
// Invoke("DelayJump", 1f);
pauseDialog.GetComponent<TweenPosition>().PlayForward();
}
But when I click on Pause Button on Scene then it as image below :
https://www.dropbox.com/s/ipnnbddren2623a/Untitled.png Player jump up when pause beacause touch screen's also running. Actually ,I never use Raycast to do this and I don't know use it how.
Answer by NikunjPopat · Jul 14, 2014 at 10:14 AM
you should use OnApplicationPause() method.
Write your pause code into OnApplicationPause() method...
Your answer
Follow this Question
Related Questions
How do I move an object with my finger?[C#] 1 Answer
A touch'es state is always Began and the position doesn't change 1 Answer
Drag a ball to add force to a ball by touch screen 1 Answer
Transitioning from different number of touches causes behavior overlap 0 Answers
Unity touch not working correctly 0 Answers