How to destroy initiated Network Object?

Hello I try to destroy initiated Network Objects.

This is my code:

var gate_team_1 = Network.Instantiate(gates, gates_spawnpoint_team_1, transform.rotation, 0);
var gate_team_2 = Network.Instantiate(gates, gates_spawnpoint_team_2, transform.rotation, 0);
Debug.Log("gates initialized, waiting 5 Seconds");
yield WaitForSeconds (5);
Network.Destroy(gate_team_1);
Network.Destroy(gate_team_2);

Its initiating fine, but after the 5 seconds I get the following error:

MissingMethodException: Method not found: 'UnityEngine.Network.Destroy'.

I saw that u have to call Destroy on the Initiated Object. But I dont like to give so many prefabs some scripts. Isnt there a way like I do?

Thanks

2 Answers

2

Look again at the scripting reference: http://unity3d.com/support/documentation/ScriptReference/Network.Destroy.html . It says it takes a ViewID as input, then gives an example:

Network.Destroy(GetComponent(NetworkView).viewID);

var gate_team_1 = Network.Instantiate(gates, gates_spawnpoint_team_1, transform.rotation, 0);
this code will not store a pointer to the instantiate object if that was your intention

You can call Network.Destroy (networkView.viewID); if you attach the script to the gates object(works with prefab too). for example:

function Update () {
if (GateHitPoints<=0) Network.Destroy (networkView.viewID);
}