IOS Hit Test Not working

Hi All, This should work and looks really simple, but for some reason it isn’t working when using unity remote. Not sure why the hitTest isn’t hitting. Any help would be great. Thanks

public GUITexture guiRight;

voidUpdate () {

if (Input.touchCount > 0) {
for(inti = 0; i < Input.touchCount; i++) {
Toucht = Input.GetTouch(i);

if (guiRight.HitTest((t.position),Camera.main)) {
Debug.Log(“Touching Right Control”);
break;
}

}
}

Is the code you posted a direct copy and paste? It looks as if it needs a couple of spaces here and there.

Here is the full code which the mouse click works fine.

usingUnityEngine;
usingSystem.Collections;

[RequireComponent(typeof (Rigidbody2D))]
[RequireComponent(typeof(BoxCollider2D))]
publicclassTouchControls : MonoBehaviour {

publicGUITextureguiLeft;
publicGUITextureguiRight;
//publicGUITextureguiJump;
publicGUITextureguiPause;

publicAudioClip[ ] jumpClips;

publicfloatmoveSpeed = 10f;
publicfloatjumpForce = 500f;
//publicfloatmaxJumpVelocity = 500f;
publicfloatmaxSpeed = 5f;

publicboolfacingRight = true;
boolpaused = false;

Animatoranim;

boolgrounded = false;
publicTransformgroundCheck;
floatgroundRadius = 0.2f;
publicLayerMaskwhatIsGround;

privateCameracam;
privateGUIElementhitObject;
//privateGUILayerHitGuiLayer;
privateGUILayertest;

publicboolmoveLeft, moveRight, doJump = false;

voidAwake(){

cam = Camera.main;
anim = GetComponent ();
test = Camera.main.GetComponent();
//HitGuiLayer = Camera.main.GetComponent;

}

//Usethisforinitialization
voidStart () {

}

voidUpdate () {

if (Input.touchCount > 0) {
for(inti = 0; i < Input.touchCount; i++) {
Toucht = Input.GetTouch(i);

if (guiLeft.GetScreenRect().Contains(t.position)) {
Debug.Log(“Touching Left Control”);
//guiLeft.guiTexture.pixelInset.x += 10;
Jump();
moveLeft = true;
break;
} //else

if (guiRight.HitTest((t.position),Camera.main)) {
Debug.Log(“Touching Right Control”);
//guiLeft.guiTexture.pixelInset.x += 10;
Jump();
moveRight = true;
break;
} //else

if (guiPause.HitTest(cam.ScreenToWorldPoint(t.position))) {
//guiPause.guiTexture.pixelInset.x += 10;
Debug.Log(“Touched the Pause Button”);

Pause();
break;

// }

Shooting();

//Arewetouchingthejumpbutton?
/if (guiJump.HitTest(t.position, Camera.main)) {
Debug.Log(“Touching Jump Control”);
doJump = true;
}
/

}

if (t.phase == TouchPhase.Ended) {
//Stopallmovement
//if (moveLeft) guiLeft.guiTexture.pixelInset.x -= 10;
//if (moveRight) guiRight.guiTexture.pixelInset.x -= 10;
//if (paused) guiRight.guiTexture.pixelInset.x -= 10;

doJump = moveLeft = moveRight = false;
//moveLeft = moveRight = false;

//rigidbody2D.velocity = Vector2.zero;
}
}
}

if (Input.GetMouseButtonDown(0)) {

Shooting();

if (guiLeft.HitTest(Input.mousePosition, cam)) {

Debug.Log(“Touching Left Control”);
Jump();
moveLeft = true;
}

if (guiRight.HitTest(Input.mousePosition, cam)) {
Debug.Log(“Touching Right Control”);
Jump();
moveRight = true;
}

/*
if (guiJump.HitTest(Input.mousePosition, Camera.main)) {
Debug.Log(“Touching Jump Control”);
doJump = true;
}
*/

if (guiPause.HitTest(Input.mousePosition, cam)) {
Debug.Log(“Touched the Pause Button”);

Pause();

}
}

if (Input.GetMouseButtonUp(0)) {
doJump = moveLeft = moveRight = false;
//rigidbody2D.velocity = Vector2.zero;

}
}

voidShooting(){

//5 - Shooting
boolshoot = Input.GetButtonDown (“Fire1”);
shoot |= Input.GetButtonDown (“Fire2”);
//Careful: ForMacusers, ctrl + arrowisabadidea

shoot = true;

if (facingRight) {
WeaponScriptweapon = GetComponent ();
if (weapon != null) {
//falsebecausetheplayerisnotanenemy
weapon.Attack (false);
}
}

if (shoot) {
WeaponScriptweapon = GetComponent ();
if (weapon != null) {
//falsebecausetheplayerisnotanenemy
weapon.Attack (false);
}
}

}

voidPause() {

//inversethepause
paused = !paused;

if (paused)
Time.timeScale = 0;
else
Time.timeScale = 1;

}
voidFixedUpdate() {

//checkifweareontheground = trueorfalse
grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);

//iftruethenontheground
anim.SetBool (“Ground”, grounded);

anim.SetFloat (“VSpeed”, rigidbody2D.velocity.y);

if (moveLeft) {
//settheanimatorvariabletotheabsvalueofspeed
anim.SetFloat(“Speed”,Mathf.Abs(-moveSpeed));

rigidbody2D.velocity = -Vector2.right * moveSpeed;
//rigidbody2D.velocity = newVector2 (-moveSpeed * maxSpeed, rigidbody2D.velocity.y);

doJump=true;

if (facingRight)
Flip ();

}

if (moveRight) {
//settheanimatorvariabletotheabsvalueofspeed
anim.SetFloat(“Speed”,Mathf.Abs(moveSpeed));

rigidbody2D.velocity = Vector2.right * moveSpeed;
//rigidbody2D.velocity = newVector2 (moveSpeed * maxSpeed, rigidbody2D.velocity.y);

doJump=true;

if (!facingRight)
Flip ();

}

if (doJump) {
//if (rigidbody2D.velocity.y < jumpForce) {
//rigidbody2D.AddForce(Vector2.up * jumpForce);
//Debug.Log(“Jumping…”);
rigidbody2D.AddForce(newVector2(0,jumpForce));

//Playarandomjumpaudioclip.
//inti = Random.Range(0, jumpClips.Length);
//AudioSource.PlayClipAtPoint(jumpClips*, transform.position);*
//audio.PlayOneShot(jumpClips*,0.7f);*
//} else {
doJump = false;
//}
}
}
//Updateiscalledonceperframe
voidFlip () {
//reversethefacingflag
facingRight = !facingRight;
//getthelocalscale
Vector3theScale = transform.localScale;
//flipthescale
theScale.x *= -1;
//assignthenewflippedscale
transform.localScale = theScale;
}
voidJump(){
//if (rigidbody2D.velocity.y < jumpForce) {
//rigidbody2D.AddForce(Vector2.up * jumpForce);
//Debug.Log(“Jumping…”);
//rigidbody2D.AddForce(newVector2(0,jumpForce));
//Playarandomjumpaudioclip.
inti = Random.Range(0, jumpClips.Length);
AudioSource.PlayClipAtPoint(jumpClips*, transform.position);*
//audio.PlayOneShot(jumpClips*,0.7f);*
}
}

I just tried unity remote 4 on android and it worked fine, but still doesn’t work on IOS

I’m just guessing, but wonder if the screen resolution of the iOS device and the window resolution of the game view in the editor are completely different? Perhaps Debug.Log the position that the touch returns, and compare against the size/position of the GUITexture.