Returning Coordinates when clicking on a QUAD

First, Thanks for taking the time to read my post and provide a clear answer… or any tips you can provide.

#Setup
I have a Main Camera and a Quad ( its a bit stretched ). And a texture on the QUAD of a simple picture i made in photoshop that I drew a start button and an exit button. Simple, right? I have a MouseClick C# script on the quad that checks for OnMouseDown ()

#I want to

  1. OnMouseDown ()… I want to find out if they clicked the start button box, or the exit button box
  2. Should I be trying to find the x,y coordinate of the JPG when clicked? I am just not sure the best way to go about finding out if they clicked the simple buttons of the texture on the quad?
  3. Is Raycast, the solution I seek? How would that translate to whether or not they are clicking the buttons instead of simply just clicking the quad anywhere?

Because, I did draw this in photoshop… I do know the exact coordinates on the JPG where the button boxes are, but Unity has it’s own coordinate system.

I did find this bit of code in the UnityAPI:

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Update() {
        if (!Input.GetMouseButton(0))
            return;
        
        RaycastHit hit;
        if (!Physics.Raycast(camera.ScreenPointToRay(Input.mousePosition), out hit))
            return;
        
        Renderer renderer = hit.collider.renderer;
        MeshCollider meshCollider = hit.collider as MeshCollider;
        if (renderer == null || renderer.sharedMaterial == null || renderer.sharedMaterial.mainTexture == null || meshCollider == null)
            return;
        
        Texture2D tex = renderer.material.mainTexture;
        Vector2 pixelUV = hit.textureCoord;
        pixelUV.x *= tex.width;
        pixelUV.y *= tex.height;
        tex.SetPixel(pixelUV.x, pixelUV.y, Color.black);
        tex.Apply();
    }
}

But, I do not understand Renderer renderer = hit.collider.renderer and down… I think this is what I need. If someone could possibly give me a brief introduction in English on what the code lines are doing…

Use unity 4.6 UI. All what you’re doing is just a waste of time to be honest. I used to do that in the old unity.

1). update your unity to 4.6 if you haven’t already done so

2). right click in the hierarchy and go to UI > Canvas

3). right click on the canvas and go again to UI > Image and add the “Main Menu” image or just add text.

4). right click on the canvas and go again to UI > Button. Then mess around and see what happens.