Hi,
I’m working on a gun for a multiplayer. When I spawn a projectile the guns spawns it twice this should be just one time. I have a weapon control script:
public void Fire (int myID) {
foreach (Weapon wp in weapons) {
wp.Fire (myID);
Debug.Log (myID);
}
}
a weapon script:
public void Fire (int myID) {
GetComponent<NetworkView>().RPC ("Shoot", RPCMode.AllBuffered, myID);
}
[RPC]
public void Shoot (int myID) {
GameObject thisProjectile;
thisProjectile = (GameObject) Network.Instantiate (projectile, transform.parent.position + offSet, transform.parent.rotation, 2);
thisProjectile.GetComponent<Projectile>().setProjectile(myID, speed);
}
and a projectile script:
void Update () { //A quick fix for now
if (myOwner == 0)
Destroy (gameObject);
}
public void setProjectile (int owner, Vector3 speed) {
myOwner = owner;
myRigidbody = gameObject.GetComponent<Rigidbody>();
myRigidbody.AddForce (speed);
}
there is just one weapon script attached to my player and his children, both the projectiles spawn at the same spot but one doesn’t get assigned an ID and stays 0. I’ve placed a Debug.Log in every void in the chain and nothing get’s called twice. For now I can just destroy the projectiles with the owner 0. but it annoys me that it is spawning twice and I can’t figure out why it does that.