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.

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