Adding touch control to existing 2D control system.

Hi. I have a working game using a 2D control system which all works great on pc. I’m trying to port this to touch screen now and it’s proving a pain.

I don’t want to create a new control system as the game depends on the current setup.

Right now i use:

if( Input.GetKey( KeyCode.RightArrow ) )

and

else if( Input.GetKey( KeyCode.LeftArrow ) )

Whats the best way to add touch controls into that code ?

I would like to either use something like the Standard Assets (Mobile) SidescrollSetup or 3 button boxes eg. left, right and jump.

I’ve spent 6 hours trying to get the Standard Assets one working within my code.

If someone could give me any advice or point me towards a tutorial (I’ve watched 6 and they didn’t help) I would be extremely grateful.

Okay, I can help you make the touch input button :slight_smile: first make a GUI texture wich will be your touchscreen button. And then add this part to your code’s input part. (Sorry I am using ipad so I cant made code section so im just gonna write it)

var TouchButton : GUITexture; //drag here your gui texture button

function Update(){

for (var evt : Touch in Input.touches) {

var HitTest1 = TouchButton.HitTest(evt.position);

if (evt.phase == TouchPhase.Began) {

if(HitTest1){ //here add what will happen if this button gets touch

Answer me did it work! :slight_smile: