- Home /
Getting texel on a gameobject
Hi.
I am trying to draw to a texture when clicking on a game object - but after getting the local position of the click I can't figure out how to get the values I should draw to, as I am getting values that does not represent the texture (and 0.0 is in the middel of the gameobject I am clicking).
So far I have this:
Vector2 input = new Vector3(Input.mousePosition.x,Input.mousePosition.y);
RectTransform t = this.gameObject.GetComponent<RectTransform>();
Vector2 output;
bool wasHit = RectTransformUtility.ScreenPointToLocalPointInRectangle(t,input,Camera.main, out output);
Vector2 localpoint = output;
Debug.Log ("out:"+input.ToString() +" local: "+localpoint.ToString());
Vector2 uv;
//= value * scale * textureSize;
uv.x = localpoint.x * 1*512 ;
uv.y = localpoint.y* 1*512 ;
int texelX = Mathf.FloorToInt(uv.x );
int texelY = Mathf.FloorToInt(uv.y );
However the texel values are clearly wrong, with 0.0 still being in the middel of the gameobject instead of the bottom right corner as I want. I seem to be missing some math understanding here, so any help would be very much appriciated!
Your answer
Follow this Question
Related Questions
How can I draw an array of data (640x480) very fast ? 5 Answers
Draw Semi-transparent texture. 1 Answer
Draw triangles on texture 1 Answer
Drawing a Texture on top of another Texture 2 Answers
Assigning UV Map to model at runtime 0 Answers