Alternative to SendMessage()? / Mobile Optimization

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;
	}
}

Hello! My suggestions:

  • I would make TouchButton an abstract class (shown below),
  • or make OnTouchBegan and OnTouchEnded virtual functions in TouchButton and override in derived classes.
public abstract class TouchButton : MonoBehaviour {
  protected abstract void OnTouchBegan();

  void Update() {
    if(Input.GetTouch(i).phase == TouchPhase.Began) {
      // Instead of this.SendMessage("OnTouchBegan") just call OnTouchBegan();
      OnTouchBegan();
    }
  }
}
public class TouchButtonBackward : TouchButton {
  protected override void OnTouchBegain() {
    PlayerMovement.backward = 1;
  }
}

Keep in mind Debug calls are quite heavy.