Calling Function in other Script via Touch => iOS Crash

I´am porting a Standalone to iOS, at the moment I have problems with moving my code from GUI.Buttons to Touch.

I have a GameObject, with a guiTexture and a Script attached, that calls a function in another Script when the guiTexture is touched. If I touch the guiTexture the iOS App crashes, I´am not calling any fancy stuff in that other script it is just a Debug.Log.

#pragma strict
private var gui : GUITexture;

function Start()
{
  gui = GetComponent( GUITexture );
}

function Update()
{
 if(Input.touchCount > 0)
  {
    for(var i : int = 0; i < Input.touchCount; i++)
     {
       var touch : Touch = Input.GetTouch(i);
       if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position))
        {
          var otherScript : TheOtherScript = gameObject.GetComponent(TheOtherScript);
          otherScript.CallMyFunction();
          Debug.Log("guiTexture Touched");
        }
     }
  }
} 

And here the Function in “TheOtherScript” Script:

function CallMyFunction()
{
Debug.Log("CallMyFunction executed");
}

You should make sure that the component TheOtherScript is found before using it, unless you are sure it exists (with RequireComponent for instance). I don’t see why it would crash otherwise.

A good way to debug a build project is to use throw / catch (well that’s always good) and use CreatePrimitive according to the exception you get, or anything visual, you could display the exception with a gui also. Just don’t forget to remove it before the final release.