- Home /
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");
}
Answer by Berenger · Apr 25, 2012 at 03:44 PM
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.
That was the problem, Thanks Berenger! Find other GameObject, find TheOther Script, Call$$anonymous$$yFunction.
Your answer
Follow this Question
Related Questions
move a gameobject from a GUITexture 0 Answers
add is not a member of UnityEngine.Component 5 Answers
TWO GUI texture that doesn't work together 0 Answers
Call GUITexture and script 1 Answer
Altering Z position of guiTexture through code IOS? 1 Answer