Trying to create a button

Hello,

I am trying to create a button for my IOS game which for some reason I find harder then I would expect. I understand that it is not recommended to use OnGUI so I created a GUITexture with the following script attached to it.

#pragma strict
var playButton : GUITexture;
var level : String;
private var touch : Touch;

function Start () {
}

function Update () {
	for (touch in Input.touches){
		var buttonHitTest = playButton.HitTest(touch.position);
			if(buttonHitTest  touch.phase == TouchPhase.Ended){
				Debug.Log("Play!!!");
				Application.LoadLevel(level);
			}
	
	}
}

When I click this button it sometimes does what it is supposed to do but sometimes it doesn’t react at all, which off course is not the desired effect. Could someone maybe help me out here.

Kind Regards,
Max Uijlings

Reasons for it not firing are usually that there is a collider in front of the btn. This is what I use.

 if (Input.touchCount == 1) 
  {	    
      var theTouch : Touch = Input.GetTouch(0);
      ////print("theTouch.position " + theTouch.position);
      var ray = Camera.main.ScreenPointToRay(theTouch.position);
      var hit : RaycastHit;
      if (Physics.Raycast(ray, hit))
      {
          ////print("oh yah");
          ////print("ray" + ray);
          ////print("hit.collider.gameObject.name" + hit.collider.gameObject.name);          
          if(hit.collider.gameObject.name == "nameYouWant")
          {
          }
      }
  }