title: Unity - Check if mouse click was inside of a rect transform
body: <p>I try to figure out if a mouse click was inside of a rect transform or not.</p>
  
  <p>Each time the user clicked on the screen, a ball will be thrown. But in case the user clicks on the pause button, no ball should be thrown. </p>
  
  <p>I tried to solve with this piece of code but it seems that only the top right quarter of the rect transform is recognized. Here's a short video to show the actual problem: <a href="https://youtu.be/gdyDBK6ubgo" rel="nofollow noreferrer">https://youtu.be/gdyDBK6ubgo</a></p>
  
  <p>Here's the code snippet: </p>
  
  <pre class="lang-c# prettyprint-override"><code>void Update() {
       //Check if user touch on display / click mouse button 
       Vector2 mousePos = new Vector3(Screen.width - Input.mousePosition.x,Screen.height - Input.mousePosition.y, 0); 
       if (Input.GetMouseButtonDown(0) &amp;&amp; props.throwable &amp;&amp; !checkCollisionWithPauseButton(mousePos) &amp;&amp; props.remainingBalls &gt; 0)
       {
           fireBall(Input.mousePosition);
       }
   }
  
   bool checkCollisionWithPauseButton(Vector3 mousePos){
       //TODO: This does not work very well
       return pauseButton.GetComponent&lt;RectTransform&gt;().rect.Contains (mousePos); 
   }
  </code></pre>
  
  <p>Here's a <a href="https://www.xup.in/dl,21380853/Bildschirmfoto_2018-01-27_um_22.02.27.png" rel="nofollow noreferrer">screenshot</a> which shows the rect transform. </p>