Last active
November 14, 2017 07:30
-
-
Save unitycoder/bcaa876a6e38d5b99e84 to your computer and use it in GitHub Desktop.
pixel world position (2D quad)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this only works if ScaleCamera has PixelsToUnits=1