I’m trying to get the UV coordinates from the texture on one face of a standard Unity cube, and then based on those coordinates, use GetPixel on another texture.
My problem is that the UV coordinates aren’t working the way I expect. They start at (0,0) on the bottom left and go to (1,1) at the top right, correct? However, that’s not working. Instead, I get weird results. The bottom left is (1,1), the top right is also (1,1), near the center is (0.5, 0)…I just don’t understand it.
I have a cube in the inspector, a texture assigned to it, and a “SelectRegion” script. Here’s the code I’m using for getting the UV coords:
function Update () {
if (Input.GetMouseButtonDown(0))
{
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray, hit, 15))
{
if (hit.transform.tag == "MainCube")
{
var pixelUV = hit.textureCoord;}
}
I’d greatly appreciate any help you could give me! Thank you!