How does collision work on network. every time i seem to fire on the server side it destroys the cube that ive targeted, but over on the client side it says ive destroyed the ones in the middle.
this is my script for destroy cube
using UnityEngine;
using System.Collections;
public class DestroyCube: MonoBehaviour
{
private Game game;
void Start ()
{
game = (Game)GameObject.Find("GameManager").GetComponent("Game");
}
void OnTriggerEnter(Collider other)
{
if (Network.peerType == NetworkPeerType.Server)
{
if (other.tag == "Bullet")
{
string shipName = ((Bullet)other.GetComponent("Bullet")).getFiredBy();
Debug.Log("Bullet fired by " + shipName + " has hit " + gameObject.name);
GameObject ship = GameObject.Find(shipName);
// remove the bullet from the bullet list
game.removeBullet(other.gameObject);
// tell all clients to destroy the bullet
game.getNetworkView().RPC("DestroyBullet", RPCMode.Others, other.gameObject.name);
// destroy bullet on server
Destroy(other.gameObject);
// tell all clients to destroy the cube
game.getNetworkView().RPC("DestroyCube", RPCMode.Others, gameObject.name);
// destroy cube on server
Destroy(gameObject);
}
}
}
}
which is then called from a RPC Function from another script
[RPC]
public void DestroyCube(string cubeName)
{
GameObject cube = GameObject.Find(“DestroyableCube”);
if (cube != null)
{
Debug.Log("Destroying Cube " + cubeName);
DestroyCube cubeScript = (DestroyCube)cube.GetComponent("DestroyCube");
Destroy(cube);
}
}