- Home /
Code works in editor, but not in built game.
Hi everyone.
I have a script that changes the character model AND attached camera from one to another when you press "fire2" There is a camera attached to each model and i want this camera, when enabled, to activate the camera it needs and disactivate and destroy the gameObject of the other. Its a little hard to understand me probably... so here is the code.
var explosion : Transform;
static var destroying = false; var otherClip: AudioClip; var HitClip: AudioClip; var PacManPrefab: Transform; private var timeupjet = false; var pmCamera : Transform; var jetCamera : Transform; var Jet = false;
function Awake() { timeupjet = false; }
function Update() { if(timeupjet == true) { gameObject.active = false; var pacman = Instantiate(PacManPrefab, transform.position, transform.rotation); jetCamera.GetComponent(AudioListener).enabled = false; jetCamera.gameObject.active = false; pmCamera.gameObject.GetComponent(AudioListener).enabled = true; pmCamera.gameObject.active = true; Destroy(gameObject); Destroy(gameObject); }
if(destroying == true) { levelstatus.boxescollected += 1; var exp = Instantiate (explosion, transform.position, Quaternion.identity); audio.clip = otherClip; audio.Play(); destroying = false; destroying = false; }
if(Input.GetButtonDown("Fire2")) { timeupjet = true; }
}
function OnControllerColliderHit (hit : ControllerColliderHit) {
if(hit.gameObject.tag == "Box") { Destroy(hit.gameObject); destroying = true; }
if(hit.gameObject.tag == "Laser")
{
Destroy(hit.gameObject);
audio.clip = HitClip;
audio.Play();
}
}
@script RequireComponent (CharacterController)
In the editor it does what i want it to do, where it de-activates and destroys the Jet Prefab and spawns and activates the PacMan Prefab. When i build it however, the camera still stays in the same place, even though its (supposed to be) destroyed. What am i doing wrong? thanks, alias
Answer by Unamine · Feb 14, 2011 at 11:56 PM
Review any code that you see repeated twice destroying the variable, try putting her state only once, and also see uppercase and lowercase letters in the code, depending on the appointment of the script, you may be referring to wrong
Hope this helps
Thanks for your answer. But how would that explain why it works perfectly in the editor, but not in the built game?
Your answer
![](https://koobas.hobune.stream/wayback/20220613104427im_/https://answers.unity.com/themes/thub/images/avi.jpg)