- Home /
iOS Build Error, runs normal in play mode
I want to build a project using iOS in the unity
The project I created runs normal in play mode. But when it comes to be built in Unity Builder it shows up errors like this
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection and so on.... The question is why this happens? I run the project in the play mode and nothing goes wrong... someone help me please...thx :)Assets/Script/Script PreBattle.js(21, 65): BCE0019: 'OnGUI' is not a member of 'UnityEngine.Component'. Assets/Script/Script PreBattle.js(26, 58): BCE0019: 'OnGUI' is not a member of 'UnityEngine.Component'. Assets/Script/Script PreBattle.js(30, 56): BCE0019: 'OnGUI' is not a member of 'UnityEngine.Component'. Assets/Script/Script PreBattle.js(36, 56): BCE0019: 'OnGUI' is not a member of 'UnityEngine.Component'. Assets/Script/Script PreBattle.js(42, 56): BCE0019: 'OnGUI' is not a member of 'UnityEngine.Component'. Assets/Script/Script PreBattle.js(48, 56): BCE0019: 'OnGUI' is not a member of 'UnityEngine.Component'. Error building Player because scripts had compiler errors Unity.Editor.HostView:OnGUI() Exception: Error building Player because scripts had compiler errors UnityEditor.BuildPlayerWindow.BuildPlayerWithDefaultSettings (Boolean askForBuildLocation, BuildOptions forceOptions) UnityEditor.BuildPlayerWindow.GUIBuildButtons (Boolean enableBuildButton, Boolean enableBuildAndRunButton, Boolean canInstallInBuildFolder) UnityEditor.BuildPlayerWindow.ShowBuildTargetSettings () UnityEditor.BuildPlayerWindow.OnGUI ()
pragma strict really helps :)
the problem is solved....I just type cast the component I want to show :) thx
Answer by Anxo · Jun 24, 2011 at 12:06 PM
Hi,
when you run an app on IOS it uses pragma strict. So you can not use most shortcuts.
if you add:
#pragma strict
to the begging of your code, you will get the same errors in the editor. this will help you avoid the problems.
for example, you can use
var TheMesh = GetComponent(MeshRenderer);
TheMesh.enable = false;
in the editor. but with strict on, this would give you an error like "enable is not a member of Component" so you would have to use:
var TheMesh : MeshRenderer = GetComponent(MeshRenderer);
TheMesh.enabled = false;
That won't solve the problem. If you declare The$$anonymous$$esh as a $$anonymous$$eshRenderer GetComponent($$anonymous$$eshRenderer) will still return a Component, not a $$anonymous$$eshRenderer and you'll get "Cannot convert 'UnityEngine.Component' to 'UnityEngine.$$anonymous$$eshRenderer'." there's also no need to spread this out over two lines. What you need to do is
var The$$anonymous$$esh : $$anonymous$$eshRenderer = (GetComponent($$anonymous$$eshRenderer) as $$anonymous$$eshRenderer).enabled = false
I've got similar issue, that is - build for web is fine, build for iOS couses similar errors.
For example: scene$$anonymous$$anager.transform.GetComponent("scriptScene$$anonymous$$anager").SubstractLife();
//'SubstractLife' is not a member of 'UnityEngine.Component'.
How do solve this problem?
Look at the comment right above yours. SubstractLife is not a member of Component, so you must cast it as SubstractLife.
(scene$$anonymous$$anager.transform.GetComponent(scriptScene$$anonymous$$anager) as scriptScene$$anonymous$$anager).SubstractLife();
Joshua, it doesn't need to be so verbose.
scene$$anonymous$$anager.GetComponent.<scriptScene$$anonymous$$anager>().SubstractLife();
is fine. I mean, it has a typo and uses camelCase where PascalCase would be standard, but it should compile.