I have a GUITexture button im trying to get working from a mobile app im working on for android. Im trying to be able to touch the button have it display “TOUCHED” in the Debug.Log. The Problem is that when i touch the GUITexture button, the only place that it registers the touch is in the top right corner of the GUITexture Button. This is the code i have so far:
private var gui : GUITexture;
private var defaultRect : Rect;
private var guiTouchOffset : Vector2;
function Start(){
gui = GetComponent( GUITexture );
// get where the gui texture was originally placed
defaultRect = gui.pixelInset;
// get our offset for center instead of corner
guiTouchOffset.x = defaultRect.width;
guiTouchOffset.y = defaultRect.height;
}
function Update(){
var count = Input.touchCount;
// account for the offset in our calculations
for (var i: int = 0; i < count; i++){
var touch : Touch = Input.GetTouch(i);
var guiTouchPos : Vector2 = touch.position - guiTouchOffset;
if (gui.HitTest( touch.position )){
Debug.Log("Touched");
gui.pixelInset.x = guiTouchPos.x;
gui.pixelInset.y = guiTouchPos.y;
}
}
}
any help Is greatly appreciated. This thing has been troubling me for the longest time now. Thanks