- Home /
Destroying GameObject in NetworkBehavor with Javascript
I'm incredibly frustrated I have worked for 3 and a half hours trying what feels like every different method in the scripting API. And it still doesn't work, unless I remove he NetworkBehavior, but I kind of need to tell the other players when I explode! lol! Here is my current code.
function OnCollisionEnter(collision : Collision) {
audio1.Play();
var instance : Rigidbody = Instantiate(explosion, explosionPrefab.position, explosionPrefab.rotation);
CmdDestroy(netId);
}
@Command
public function CmdDestroy(netID) {
var ship : GameObject = NetworkServer.FindLocalObject(netID);
NetworkServer.Destroy(ship);
}
I learned that it is important to use commands for the server, because the client shouldn't destroy it on its own of something. If this script won't work then my game is done. I'm planning on using these types of scripts to convert my movement and things like that to be compatible with multiplayer. What am I doing wrong? I can't get it to do anything! it never explodes no matter what command I use, the explosion is never created, and the player is never destroyed, and I have no clue whats wrong with it.