- Home /
Question by
corriedotdev · Apr 07, 2014 at 12:55 AM ·
c#mobiletouchguitexture
Touch gui texture buggy
I'm trying to press a gui texture on screen to allow the game to pause. Then presses it again and i unpauses it. I have written the following script which does the job, however its buggy and doesnt always work. Any tips?
using UnityEngine;
using System.Collections;
public class pause : MonoBehaviour {
public Texture2D texture1; // Inital texture for the button
public Texture2D texture2;
public bool paused = false;
void Start ()
{
guiTexture.texture = texture1; // gui texture is made into button1
}
void Update () // If the screen is touched
{
foreach (Touch touch in Input.touches)
{
if (guiTexture.HitTest(touch.position) && paused == false) // If the gui texture is touched then
{
guiTexture.texture = texture2;
paused = true;
Time.timeScale = 0;
}
else if (guiTexture.HitTest(touch.position) && paused == true) // until the player stops touching the screen
{
guiTexture.texture = texture1;
paused = false;
Time.timeScale = 1;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Multi touches problem 0 Answers
Android 2D multitouch joystick + buttons 0 Answers
IOS GUI slider 1 Answer
Input.GetTouch(index) is NOT the fingerID 1 Answer
Turning touch to rotation 1 Answer