- Home /
Destroying the bullet over a photon network
void OnTriggerEnter(Collider myTrigger){
if (myTrigger.gameObject.tag == "bullet" && photonView.isMine){
playerHealth -= 1;
Debug.Log ("player health:" + playerHealth);
photonView.RPC ("DestroyBullet", PhotonTargets.All, myTrigger.gameObject);
if (playerHealth <= 0){
PhotonNetwork.Destroy(this.gameObject);
}
}
}
[RPC]
void DestroyBullet(gameObject go)
{
PhotonNetwork.Destroy(go);
}
So i'm trying to have it when the bullet hits your player on your client, the bullet gets destroyed everywhere. To do this i'm sending out an RPC when the bullet collides with the player and I want to pass in the collider to the rpc function but I'm getting the error "The type or namespace name `gameObject' could not be found. Are you missing a using directive or an assembly reference?"
Any help?
Answer by jtsmith1287 · Sep 04, 2014 at 03:58 PM
I know this is old, but for other people that run into this issue, do NOT put a photonView on a bullet. That's super slow and unnecessary. Just use an RPC call to create a bullet with velocity on each client, and use your server, or master client, to detect if the bullet hits, and then send an additional RPC to handle damage and destroying of the bullet.
If there's no PhotonView on the projectile, how do you call an RPC to destroy the projectile?
You give the bullet an owner member, and call the RPC via the owner.
Answer by Nanobrain · Feb 22, 2014 at 01:37 AM
I believe this is your problem:
void DestroyBullet(gameObject go)
The 'G' should be capitalized like this:
void DestroyBullet(GameObject go)
[g]ameObject is not a class, at least not in Unity's API. But, [G]ameObject is.
@Nanobrain is correct, that needs to be a capital G so fix that bit. Is your bullet moved via physics at high speed?
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A) && Time.time > nextFire || shootLeft && Time.time > nextFire){
nextFire = Time.time + fireRate;
GameObject bullet = PhotonNetwork.Instantiate("BulletNetworking", transform.position, Quaternion.AngleAxis(-90, Vector3.forward), 0);
bullet.rigidbody.AddForce(transform.right * puffSpeed);
"puffSpeed" tells us nothing; what is the speed? Did you search UA for 'high speed collision fix' there's a ton of posts on that
Na I don't think it's that, because when I test to see if the RPC is being fired with a debug message nothing happens.
Answer by Lakrsv · Feb 22, 2015 at 04:06 PM
I know this is old, but you can't send GameObject's in RPCs
Answer by Remingsworth · Apr 26, 2016 at 04:24 AM
I think you need a photonview on the bullet in order for you to use RPCs on that object over the network.