0
\$\begingroup\$

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.

enter image description here

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

\$\endgroup\$
1
\$\begingroup\$

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

}
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 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 ? \$\endgroup\$ – Nathan Drake Sep 14 '15 at 13:08
  • 1
    \$\begingroup\$ 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); \$\endgroup\$ – Hash Buoy Sep 14 '15 at 13:25
  • \$\begingroup\$ 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 \$\endgroup\$ – Nathan Drake Sep 14 '15 at 13:59
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Hash Buoy Sep 14 '15 at 14:06
  • 1
    \$\begingroup\$ What was the problem ?? \$\endgroup\$ – Hash Buoy Sep 14 '15 at 15:47
1
\$\begingroup\$

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;
}
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 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 \$\endgroup\$ – Nathan Drake Sep 14 '15 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.