Tap anywhere?

Hi,

Anyone know how to code a tap-anywhere function (i.e. if any part of the screen is touched by the user)?

Thanks!

if (Input.touchCount == 1) {
// do stuff
}

or iPhoneInput.touchCount if you are not using Unity 3

Thanks, but I’m doing a tap to jump type thing, can I just use if (iPhoneTouch)?

Ok, so I’m using

if (iPhoneTouch.fingerId)
	{
		Debug.Log("screen tapped");
		
		rigidbody.AddForce (Vector3.up * 5);
	}

which throws the error

Doesn’t that need a comparison? fingerId == 1 ?

I personally would just use the if touchCount > 0…

Also, Input.GetMouseButton(0) or Input.anyKey would work on both iPhone and on the desktop. Since it seems you’re not using multitouch, these functions would be preferable for porting reasons (also, you can test in the editor without the need for the remote).

I forgot those work too…

I definitely would recommend one of the above if you are not using multi touch.

Off course, because fingerId isn’t a static variable, so you can’t use it without an actual object. So it’s not useable here.
Checking touchCount is your safest bet here (or GetMouseButton, that should work fine too).

Probably, but that wouldn’t fix that error.