Jump when touch the screen Android (GAME MADE FOR PC)

Hi guys, someone was so friendly to give me this code for my platform game but i would like to make it for android and what I want is that when someone touches the screen the character jumps, this game is made for pc and i realy don’t know how i should change this to work on android

ty in advance!

…CODE…

var speed: float = 2; // move speed

var jumpSpeed: float = 12; // initial jump speed

var gravity: float = 30;

private var cc: CharacterController;

private var vSpeed: float;

function Update(){

var moveDir = transform.forward * speed; // calculate the horizontal speed

if (!cc) cc = GetComponent(CharacterController); // get the CharacterController

if (cc.isGrounded){ // when grounded…

vSpeed = 0.0;  // vSpeed is zero...

if (Input.GetButtonDown("Jump")){ // unless the character jumps

  vSpeed = jumpSpeed; 

}

}

vSpeed -= gravity*Time.deltaTime; // apply a physically correct gravity

moveDir.y = vSpeed; // add the vertical speed

cc.Move(moveDir*Time.deltaTime); // and finally move the character

}

All you need to change is the (Input.GetButtonDown(“Jump”)).

You can use Input.GetTouch for this. But You can also use Input.GetMouseButton.

Personally I use the latter for my apps. Seems to work fine on all devices.

Not sure if it also works on iOS. Haven’t tested that yet.

Check out the unity script reference for info on these functions.

All you need to change is the (Input.GetButtonDown(“Jump”)).

You can use Input.GetTouch for this. But You can also use Input.GetMouseButton.

Personally I use the latter for my apps. Seems to work fine on all devices.

Not sure if it also works on iOS. Haven’t tested that yet.

Check out the unity script reference for info on these functions.

you need something like this (please check as correct answer if this works for you):

foreach (Touch touch in Input.touches)
		{
            if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
			{
				vSpeed = jumpSpeed;
			}
		}

foreach (Touch touch in Input.touches)
{
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
{
vSpeed = jumpSpeed;
}
}

So 4 errors: line 14 (foreach…) 2 errors: error 1: expecting ) found ‘touch’.
error 2: Unexpected token: ).

line 16 (if…) 1error: Unexpected token: if.
line 18 (vSpeed…) 1error: expecting :, found ‘=’

so it didn’t realy work, but do you you think you could fix those 4 errors?

can we use a simple gui button? or a gui button for easy things like shooting?