- Home /
I get an error on build but not when I run the game in the Editor. iPhone.
Hi. I am working on a game and everything runs fine when I test it using Unity Remote. I can play the game while while controlling it with the iPhone and watch it run in the editor.
But when I try to build the game I get the following error: Error building Player because scripts had compiler errors
The Error it is refearing to is the following: Assets/MyScripts/SpawnScript.js(42,73): BCE0019: 'NewParent' is not a member of 'UnityEngine.Component'.
Now I understand where the error is pointing me. What I dont understand is why does it run fine when I test it in the editor using the play button.
The following script is what the error is referring to:
if(hit.transform.gameObject.name == ThisTransform)
{
var EntryScript = EntryGameObject.GetComponent(EntryScript);
if(EntryScript.NewParent.childCount == 0)
{
var NewParent : Transform = EntryScript.NewParent;
CloneBox.transform.parent = NewParent;
filled = false;
print(hit.transform.gameObject.name);
}
}
What I am doing here is assigning a new parent to a instantiated clone. This has to be dynamic because the parent often changes. And who the new parent should be is determined by the EntryScript on EntryGameObject. Again, this all works perfectly fine when tested in the editor.
Answer by Eric5h5 · Jan 01, 2011 at 04:00 PM
When using Javascript on iPhone/Android, put "#pragma strict" at the top of all your scripts, and fix any resulting dynamic typing issues. GetComponent returns Component, so you have to cast that as the correct type instead of relying on dynamic typing. Using generics is usually the easiest way (and also you should use the convention of lowercase for variable names, which makes things less confusing):
var entryScript = entryGameObject.GetComponent.<EntryScript>();
Thank you.
I am sure what you said made sense but I did not understand most of it. The #pragma strict is interesting and I get that, I saw the syntax changes in your script exsample and it worked. I did not get your explination but I am greatful for your help.
The #pragma strict I had to turn back off after this fix because it gave me an error on my Instantiate. Can not convert object to game object. but when I turn strict off it will build.