# Limit the boundary of Touch

a game that I currently working on is in a way that player should actually draw a rainbow on the screen by tap and drag gesture in order to make a hills for the car.

but the issue that i currently facing on is if the player wants to pause the game by touching the right most button on the screen above, the game will stop but the hill that he was drawn will remove. I actually not have any idea how can i put exception for that button on the screen because everytime i calculate the whole pixels on the screen for drawing hills. do you have any idea how can i solve this issue ?

btw, this is my code if it's required : http://pastebin.com/VnLAQbzW

## 2 Answers

Hey the game is coming along nice :)

Ok so here is the simplest way to solve this problem. Check if the touch is inside a particular rectangular area on the screen and then only execute the rest of the Update function. Also you can add an additional boolean as Exerion has mentioned in his answer to check whether the menu screen is on.

Rect rect = new Rect(10, 10, 120, 120);

void Update()
{
if ( !rect.Contains(Input.mousePosition) || inMenu)
return;

//Rest of the code

}

• haha, thank you :-) now the new problem is everything will resize when they shown on mobile view. how can i get the size of the options button from that mobile view ? Commented Sep 14, 2015 at 13:08
• The simplest way you can do is take 20% bounding rectangle of the whole screen --- Rect rect = new Rect(0.2fScreen.width, 0.2fScreen.height, 0.8fScreen.width, 0.8fScreen.height); Commented Sep 14, 2015 at 13:25
• I just put Rect rect = new Rect((Screen.width - 0.2fScreen.width), (Screen.height - 0.2fScreen.height), 0.2fScreen.height, 0.2fScreen.height); but the problem is still exist. it will remove the previous rainbow that i've drawn Commented Sep 14, 2015 at 13:59
• i didn't understand, "it removes previous rainbow" ?? The code just takes care of touch input. Is the menu in different scene ? Can you give more information. Commented Sep 14, 2015 at 14:06
• What was the problem ?? Commented Sep 14, 2015 at 15:47

In your LineFreeDraw class create a public boolean variable:

public bool inMenu = false;


In Update() method check for this variable before anything else:

void Update()
{
if(inMenu) return;
// the rest of code here
}


Lastly, you should set this variable from the code of your button (that is not provided at the moment). Something like this: public LineFreeDraw lineFD;

public void OnButtonSettingsClick()
{
lineFD.inMenu = true;
}

• what i've wanted to mention was, when i press the options button, it will draw a hill AND pause the menu. when the player draw a new line(rainbow or hill), the previous one will erase. what I want is i just want pause the game AND keep the previous rainbow that has drawn Commented Sep 14, 2015 at 12:47