- Home /
Standalone Build Issues
In Unity, in the Game Scene, everything works perfectly fine. But then I make a build of it, and the GUI isn't working. I have a bar, telling the player how much ammo he has, and as the player shoots, the ammo goes down, and the bar gets smaller. It works fine in the game scene, but even when I update my build, it doesn't work. Is this a bug?
Here's the script (no variables):
function OnGUI () {
var hitGround = Nuke.hit;
if(canShoot){
GUI.backgroundColor = Color.blue;
GUI.contentColor = Color.white;
GUI.skin = skin;
GUI.Button(Rect(10,500,bulletsLeft*5, 30),bulletsLeft.ToString("f1"));
}
else if(!canShoot && Time.time % 2 < 1){
GUI.backgroundColor = Color.red;
GUI.contentColor = Color.white;
GUI.skin = skin;
GUI.Button(Rect(10,500,bulletsLeft*5, 30),("Gun Jam"));
}
if(gameTime >= 90){
GUI.backgroundColor = Color.yellow;
GUI.contentColor = Color.white;
GUI.skin = skin;
nukePassfield = GUI.TextField (Rect (10, 10, 200, 20), nukePassfield, 25);
}
if(shot && Time.time % 2 < 1 && !hitGround){
GUI.backgroundColor = Color.red;
GUI.contentColor = Color.white;
GUI.skin = skin;
GUI.Button(Rect(10,10,Screen.width,Screen.height),("Prepare for Fallout"));
GUI.backgroundColor = Color.red;
GUI.contentColor = Color.white;
GUI.skin = skin;
GUI.Button(Rect(10,10,Screen.width,Screen.height),("Prepare for Fallout"));
}
if(Time.time % 10 < 1 && hitGround){
GUI.backgroundColor = Color.red;
GUI.contentColor = Color.white;
GUI.skin = skin;
GUI.Button(Rect(10,10,Screen.width,Screen.height),("Game Over"));
GUI.backgroundColor = Color.red;
GUI.contentColor = Color.white;
GUI.skin = skin;
GUI.Button(Rect(10,10,Screen.width,Screen.height),("Game Over"));
}
GUI.backgroundColor = Color.red;
GUI.contentColor = Color.white;
GUI.skin = skin;
if(!nukeUnlocked) return;
if(GUI.Button(Rect(10,400,50, 30),("Nuke"))){
Instantiate(nuke, nukeSpawnPoint.position, nukeSpawnPoint.rotation);
Instantiate(nuke, nukeSpawnPointTwo.position, nukeSpawnPointTwo.rotation);
shot = true;
}
}
Well, maybe not. Depends on exactly how the thing works! There are certain things which work in the editor, which do not work in builds. Usually, there are warnings in the documentation against that kind of thing, but sometimes it's just unexpected. Could you post the specific code for the ammo bar so we can have a look at it?
How does it not work? (ie: Does not display at all? Displays but nothing happens?)
What are you building it for?
maybe its just positioned off the screen?
It displays, but it doesn't update. Whenever the player fires, the number of bullets is subtracted by one, and the total number shown in the GUI goes down. The GUI displays how many bullets the player has. I think it might not have to do with the GUI part of it though, because the rest of the GUI worked when I added some things in. It might be this code:
if(Input.GetButtonDown("Fire1") && Time.time > nextFire && canShoot) {
nextFire = Time.time + fireRate;
Instantiate (projectile, transform.position, transform.rotation);
Instantiate (muzzleFlash, transform.position, transform.rotation);
hasFired = true;
JamCheck();
PlaySoundOne();
}
if(Input.GetButtonDown("Fire2") && Time.time > nextFire && spitfire && canShoot) {
nextSpitfire = Time.time + spitfireFireRate;
Instantiate (projectile, transform.position, transform.rotation);
Instantiate (muzzleFlash, transform.position, transform.rotation);
hasFiredSpitfire = true;
SpitfireJamCheck ();
PlaySoundTwo();
}
if(hasFired) {
bulletsLeft -= 1;
bulletShotCount += 1;
}
if(hasFiredSpitfire) {
bulletsLeft -= 3;
bulletShotCount += 3;
spitfireShotCount += 1;
}
The problem with this scrip is the hasfired part of the code, and it's not updating.