x


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

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 () 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 :)

more ▼

asked Jun 24 '11 at 10:01 AM

beco13 gravatar image

beco13
26 11 12 14

pragma strict really helps :)

the problem is solved....I just type cast the component I want to show :) thx

Jun 27 '11 at 08:38 AM beco13
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
more ▼

answered Jun 24 '11 at 12:06 PM

Anxowtf gravatar image

Anxowtf
1.6k 22 27 38

That won't solve the problem. If you declare TheMesh as a MeshRenderer GetComponent(MeshRenderer) will still return a Component, not a MeshRenderer and you'll get "Cannot convert 'UnityEngine.Component' to 'UnityEngine.MeshRenderer'." there's also no need to spread this out over two lines. What you need to do is

var TheMesh : MeshRenderer = (GetComponent(MeshRenderer) as MeshRenderer).enabled = false
Jun 24 '11 at 12:22 PM Joshua

I've got similar issue, that is - build for web is fine, build for iOS couses similar errors.

For example: sceneManager.transform.GetComponent("scriptSceneManager").SubstractLife();

//'SubstractLife' is not a member of 'UnityEngine.Component'. 

How do solve this problem?

Jun 24 '11 at 12:39 PM michalbigplay

Look at the comment right above yours. SubstractLife is not a member of Component, so you must cast it as SubstractLife.

(sceneManager.transform.GetComponent(scriptSceneManager) as scriptSceneManager).SubstractLife();
Jun 24 '11 at 01:42 PM Joshua

Joshua, it doesn't need to be so verbose.

sceneManager.GetComponent.<scriptSceneManager>().SubstractLife(); 

is fine. I mean, it has a typo and uses camelCase where PascalCase would be standard, but it should compile.

Jun 24 '11 at 02:29 PM Jessy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2026
x684
x366
x112

asked: Jun 24 '11 at 10:01 AM

Seen: 1905 times

Last Updated: Jun 27 '11 at 08:38 AM