Virtual directional pad

Okay, i’m using now two GUITexture to move my 2D character to left and right and i want to use only one like this image. I want to know how to calculate the axis and when the player finger touchs the right side the character goes to the right, and when he touch the left side than go to the left. i’m coding in C#

20921-linedark04.png

Assuming you setup the pixel inset so that the anchor is at the center, you can just convert the the touch position to Viewport coordinates and subtract the position from them:

var pos = Camera.main.ScreenToViewportPoint(fingerPos);
var pos = pos - transform.position;

‘pos’ will be relative to the pivot of this texture. Positive ‘y’ values will be above the pivot, positive ‘x’ values will be to the right of the pivot.