Hey there Unity Community,
Ran into this problem not sure exactly whats going on but, im simply trying to make a gameObject move left,right,up,down, based on touch inputs. Heres my code below
var speed = 1.5;
var ArrowUp: GUITexture;
var ArrowDown: GUITexture;
var ArrowLeft: GUITexture;
var ArrowRight: GUITexture;
function Update() {
if(iPhoneInput.touchCount > 0)
{
var touch: iPhoneTouch = iPhoneInput.touches[0];
if(touch.phase == iPhoneTouchPhase.Began guiTexture.HitTest(touch.position))
{
if (ArrowUp.HitTest(touch.position))
{
transform.Translate(0,speed,0);
}
if (ArrowDown.HitTest(touch.position))
{
transform.Translate(0,-speed,0);
}
if (ArrowLeft.HitTest(touch.position))
{
transform.Translate(speed,0,0);
}
if (ArrowRight.HitTest(touch.position))
{
transform.Translate(-speed,0,0);
}
}
}
}
The script is attached to my gameObject that i want to be controlled and each GUITexture Arrow is its on GUITexture object in the editor
Ive made sure ive assigned them all to their appropriate variable in the editor
and the Pixel Inset is set at 0 for both X and Y
the script isnt spitting out any problems so im not sure whats going on, ive tested this on a compiled version of my app on my iphone
i used joeyjrs movement script as a basis , everything looks like it should work but still no response from the iPhone : /
// declare all variables and remember to drag and drop your Player character Rigidbody and GUITextures into the slots in the Unity Inspector window.
var UFO : GameObject;
var Speed : float = 1.5;
var ArrowUp : GUITexture;
var ArrowDown : GUITexture;
var ArrowLeft : GUITexture;
var ArrowRight : GUITexture;
function Update () {
// begin "for" loop to check for iPhone touches and create a variable "evt" to store them in
for (var evt : iPhoneTouch in iPhoneInput.touches)
{
// hit tests: create variables to store hit test results then test for hit inside each GUITexture
var myUpHitTest = ArrowUp.HitTest(Input.mousePosition);
var myDownHitTest = ArrowDown.HitTest(Input.mousePosition);
var myLeftHitTest = ArrowLeft.HitTest(Input.mousePosition);
var myRightHitTest = ArrowRight.HitTest(Input.mousePosition);
// specify which type of iPhone Touch (Began, Stationary, Ended, etc.) to use. I chose "Stationary" so as long as I press and hold on the GUITexture button my player target moves
if (evt.phase == iPhoneTouchPhase.Stationary)
{
// nested if statements that tell what to do if each hit test is true
// make Player move up if the "ArrowUp" GUITexture button is pressed
if(myUpHitTest)
{
UFO.transform.Translate(0,Speed,0);
}
// Make Player move down if the "ArrowDown" GUITexture button is pressed
if(myDownHitTest)
{
UFO.transform.Translate(0,-Speed,0);
}
// Make Player move left if the "ArrowLeft" GUITexture button is pressed
if(myLeftHitTest)
{
UFO.transform.Translate (-Speed,0, 0);
}
// Make Player move right if the "ArrowRight" GUITexture button is pressed
if(myRightHitTest)
{
UFO.transform.Translate (Speed,0, 0);
}
}
}
}
in search of a solution i stripped the code down and resulted to a script for each GuiTexture to see if it worked
var UFO : GameObject;
var speed : float = 1.5;
var ArrowUp : GUITexture;
function Update()
{
if(iPhoneInput.touchCount > 0)
{
var touch: iPhoneTouch = iPhoneInput.touches[0];
if(touch.phase == iPhoneTouchPhase.Began guiTexture.HitTest(touch.position))
{
UFO.transform.Translate(0,speed,0);
}
}
}
still no luck
Help would be greatly appreciated as this would clear one of the big issues im having right now for my game.
Im testing all this through Unity Remote on and iPhone 2G
Thanks!
try inverting the Y component of the touch.
for instance…
if your GUIElement rect looks like Rect(34,48,64,64) and your touch.position is at Vector2(19,48) try inverting the vector2 by doing
newTouch = Vector2(touch.position.x, (Screen.height - touch.position.y))
this is also testable by just touchign the screen at the inverted position and seeing if it works.
Hey mitch, thanks for the reply! maybe im missing something but, im not using and GUIelement Rect for this, based on a few other threads others have been able to just use GUItexture and Iphonetouch codes to get a touch sensitive GUI working
I’m not sure if your suggestion will help in this case 
(Im pretty new at programming so I might be totally wrong!)
The code is simple enough to respond to my touch on the “button” Guitexture, I have it set up as a GUITexture with the script attached to it in Unity Iphone, but its not responding to any touch.