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
- OnMouseDown ()… I want to find out if they clicked the start button box, or the exit button box
- 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?
- 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…