I am completely baffled. I had a simple script attached to an empty gameobject with a camera component attached to it. This gameobject was a child of another gameobject.
here’s the script:
function DetachCamera(){
transform.parent = null;
}
The other gameobject is a tank. When it is destroyed I want to detach the camera from it and not destroy it along with the tank. Here are the functions that take care of destroying the tank:
function Explode(){
if(Network.isServer){
var wr = Network.Instantiate (wreck, rigidbody.position, rigidbody.rotation, 0);
wr.rigidbody.velocity = rigidbody.velocity;
for(var child:Transform in myTransform){
if(child.collider){
child.collider.active = false;
}
}
}
owner = myTransform.GetComponent(NetworkOwner).owner;
ownerStr = myTransform.GetComponent(NetworkOwner).ownerStr;
for(slot in spawn.players){
if(slot.gamePlayer == previousHitter ownerStr != ""){
slot.frags += 1;
}
}
if (Network.isServer ownerStr != ""){
spawn.QueueSpawn(owner, "killed");
}
audio.Stop();
spawn.UpdateScoreboard();
if(owner == Network.player){
BroadcastDetachCamera();
}else{
networkView.RPC("BroadcastDetachCamera", owner);
}
if(Network.isServer){
Network.Destroy(gameObject);
}
}
@RPC
function BroadcastDetachCamera(){
transform.root.BroadcastMessage("DetachCamera", SendMessageOptions.DontRequireReceiver);
}
But the thing is, the camera script no longer exists anywhere on my computer and is not attached to the camera, but it still works. If the tank explodes the camera’s parent is set to null. If I comment out the BroadcastMessage the camera is destroyed. What the heck is going on?? Is there an undocumented built in function called DetachCamera that does the exact same thing as my script or what is this?