My targeted platform is Windows Phone 8 and this function seems to cause quite a lot of lag. It drops the game from around 45 to 2. The scripts I have for the movement buttons are the following:
using UnityEngine;
using System.Collections;
public class TouchButton : MonoBehaviour {
// Update is called once per frame
void Update () {
if(Input.touches.Length <= 0) {
}
else {
for(int i = 0; i < Input.touchCount; i++) {
if(this.guiTexture.HitTest(Input.GetTouch(i).position)) {
if(Input.GetTouch(i).phase == TouchPhase.Began) {
Debug.Log("The touch has begun on " + this.name);
this.SendMessage("OnTouchBegan");
}
if(Input.GetTouch(i).phase == TouchPhase.Ended) {
Debug.Log("The touch has ended on " + this.name);
this.SendMessage("OnTouchEnded");
}
}
}
}
}
}
This one has multiple versions of it, one for every button on screen. (4 different)
using unityEngine;
using System.Collections;
public class TouchButtonBackward : TouchButton {
void OnTouchBegan() {
PlayerMovement.backward = 1;
}
void OnTouchEnded() {
PlayerMovement.backward = 0;
}
}