I’m working on a basic pause menu script for mobile. I’ve currently got it so that a touch sends out a raycast towards the pause button or the menu buttons. When the pause button is hit by the raycast the timescale becomes 0. The problem is, once the timescale is set to 0 no more touches are detected and I need them to be. I’ve tried setting the timescale to something really low instead of 0 and that didn’t help.
void OnClick()
{
if (this.gameObject.name == "Pause_Button")
{
PauseMenu.SetActive (true);
Time.timeScale = 0;
}
if (this.gameObject.name == "Resume")
{
PauseMenu.SetActive (false);
Time.timeScale = 1;
}
if (this.gameObject.name == "Quit")
{
Application.LoadLevel (0);
}
if (this.gameObject.name == "Options")
{
}
}
Looking for nay suggestions on how to fix this/work around this. A way to pause the game without changing the timescale or something like that.
EDIT: Code that sends OnClick as requested.
void FixedUpdate ()
{
if ( Application.platform == RuntimePlatform.IPhonePlayer ||
Application.platform == RuntimePlatform.Android )
{
if ( Input.touchCount <= 0 )
return;
// detect single touch only
Touch touch = Input.touches[0];
if ( touch.phase == TouchPhase.Began )
{
Debug.Log( 123 );
OnTouchBegan( touch.position );
}
}
else
{
if ( Input.GetMouseButtonDown( 0 ) )
{
Debug.Log(Input.mousePosition);
OnTouchBegan( Input.mousePosition );
}
}
}
void OnTouchBegan (Vector2 screenPos)
{
Ray ray = Camera.main.ScreenPointToRay( screenPos );
RaycastHit hit;
if ( Physics.Raycast( ray, out hit ) )
{
hit.collider.gameObject.SendMessage("OnClick", SendMessageOptions.DontRequireReceiver);
}
}
}
SECONDARY EDIT: Added the Debug.Log code back into it.