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