hello!
in my car game i use four gui textures to control the car. two for steering on the left and two for driving on the right. in the following script i use four hittests to check if the gui textures are touched. the strange thing is when i hold one of the driving textures i be able to steer the car without to touch over the steering textures. when i tap above the steering textures but in the same x position like the steering textures the hittest of this texture goes true.
i have this also tested with rect.Contains(touch.position) instead of HitTest. same thing.
its like a mirror of the textures. i test this all on my htc desire.
has someone an idea?
static var touchhorizontal : float = 0;
static var touchvertical : float = 0;
//var leftgui : GUITexture;
//var rightgui : GUITexture;
//var downgui : GUITexture;
//var upgui : GUITexture;
static var leftgui;
leftgui = GameObject.Find("touchbuttonleft").guiTexture;
var rightgui;
rightgui = GameObject.Find("touchbuttonright").guiTexture;
var downgui;
downgui = GameObject.Find("touchbuttondown").guiTexture;
var upgui;
upgui = GameObject.Find("touchbuttonup").guiTexture;
static var touch : Touch;
function Update () {
var count = Input.touchCount;
for(var i : int = 0;i < count; i++) {
//var touch : Touch = Input.GetTouch(i);
touch = Input.GetTouch(i);
if (leftgui.HitTest(touch.position)&touchhorizontal >= -0.5 ) {
touchhorizontal -= 0.1;
}
else if (rightgui.HitTest(touch.position)&touchhorizontal <= 0.5 ) {
touchhorizontal += 0.1;
}
else if (downgui.HitTest(touch.position)&touchvertical>= -1.0 ) {
touchvertical -= 0.1;
}
else if (upgui.HitTest(touch.position)&touchvertical<= 1.0 ) {
touchvertical += 0.1;
}
}
//////////// set back to 0 if not touched
if (leftgui.HitTest(touch.position)==false&rightgui.HitTest(touch.position)==false&count==1){
touchhorizontal=0;
}
else if (downgui.HitTest(touch.position)==false&upgui.HitTest(touch.position)==false&count==1){
touchvertical=0;
}
else if (count==0){
touchhorizontal=0;
touchvertical=0;
}
}