Skip to content

Instantly share code, notes, and snippets.

@JT5D
Forked from unitycoder/Pixel2WorldPos
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save JT5D/e707231fed0bcd0b4850 to your computer and use it in GitHub Desktop.

Select an option

Save JT5D/e707231fed0bcd0b4850 to your computer and use it in GitHub Desktop.
// quad pos: 0.5, 0.5, 0
// quad scale: 2, 1, 0
// texture size: 1280x720
Vector3 wPos = new Vector3(x,y,0); // x,y = texture pixel pos
float localX = wPos.x*2 / tex.width - 0.5f * 2; // 2 = quad transform scale
float localY = wPos.y / tex.height - 0.5f * 1;
wPos = transform.TransformPoint(new Vector3(localX, localY, 0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment