Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active November 14, 2017 07:30
Show Gist options
  • Save unitycoder/bcaa876a6e38d5b99e84 to your computer and use it in GitHub Desktop.
Save unitycoder/bcaa876a6e38d5b99e84 to your computer and use it in GitHub Desktop.
pixel world position (2D quad)
Vector3 pixelPos = new Vector3(x,y,0); // x,y = texture pixel pos
float planeWidth=transform.renderer.bounds.size.x;
float planeHeight=transform.renderer.bounds.size.y;
// convert to 0-1 uv coords
float localX = ((pixelPos.x / texWidth)-0.5f)*planeWidth;
float localY = ((pixelPos.y / texHeight)-0.5f)*planeHeight;
//Vector3 worldPos = transform.TransformPoint(new Vector3(localX,localY, 0));
Vector3 worldPos = new Vector3(localX,localY, 0);
@unitycoder
Copy link
Author

this only works if ScaleCamera has PixelsToUnits=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment