In the game I'm working on I have a simple GUI button to Start/exit the game, as well as a script that uses GUI Text to create a timer (it's a timed level). Both work accordingly when the game is played within Unity, however upon publishing, the timer fails to initiate and just displays "5:00" without changing, and the GUI button isn't present at all. I have cleaned out the build settings but am still having this issue. Any ideas what could be causing this? I'm at a loss.
You said the timer fails to initiate. One thing that can act differently in deployed mode (particularly if debugging is turned off) is that threading and coroutine situations may create differing results in deploy vs development mode. This behavior is not specific to Unity or C# and I attribute it here to the fact that the Unity logging process is expensive enough to cause significant differences when enabled/disabled. Every time a log event is generated in Unity the stack is unwound and it does add up.
I would check your assumptions around the updating or initialization of the timer. Where is it initialized? Where is it updated? Maybe you could post the relevant code?
I have a simular problem with my GUI after i published the scene. I created 2 GUI texts in the upper right corner. They are still nemed GUI text. In the script i change the text to score and the other to level. When i click play in Unity it works and when i publish it it says 2 times GUI text.
My quess is that it's in the function OnGUI() that i use.
here is the code i use
private static var Score = 0;
private static var Level = 1;
function OnGUI () { gameObject.Find ("guiLevel").guiText.text = "Level : " + Level;
guiText.guiText.text = "Score : "+Score;
GUI.contentColor = Color.black;
}
Only solution I've discovered is to rebuild the project. It's often not an issue with the script itself.
Maybe you could turn all your GUI elements to independent (or parented) "Game Objects" and attach your scrips these "game objects", rather than just having "scripts" run the show. This should resolve your memory leak when you build the game.
One thing I've found is that any assets that aren't specifically included in any scene in your project at build time won't be in your assets folder. So it could be that if you don't use the textures or similar anywhere else in your scene except programmatically instantiating it, that it's excluding the texture assets from your actual published version.
In that case, the solution is simple: just add a reference to the missing assets somewhere in your scene. That may or may not be what's going on here, but I've run into it before and thought it's worth a shot.
I've discovered that this occurs when the metadata files in the library become altered. This can occur by accident if you are often merging changes between various build versions. You may have to copy all assets to a new project folder to get them to build correctly. You can try to reimport all in your current project, however this can also corrupt your current project. So if you do choose to try this route, I'd advise you to first make a backup of your current project.