Sorry for reviving this dead post after years but I was wondering what do you think of this use case:
I have my map that is made up of blocks (think minecraft), and I want to destroy some of these blocks with bombs. Because I have about +200 blocks (and players can also create more), I thought I shouldn’t have 200 PhotonViews on each but instead destroy/instantiate and then announce via [PunRPC].
The thing is though, when I do it that way it doesn’t work?
These are my scripts for creating bombs or destroying blocks:
For creating a bomb: I just instantiate it, and then give it a velocity in the direction that I am looking at
[PunRPC]
void ThrowBomb()
{
GameObject instBomb = Instantiate(bomb, cam.transform.position, Quaternion.identity);
//GameObject instBomb = PhotonNetwork.Instantiate(bomb.name, cam.transform.position, Quaternion.identity);
Ray ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
Rigidbody bombRb = instBomb.GetComponent<Rigidbody>();
bombRb.velocity += pc.rb.velocity; //add current velocity
bombRb.angularVelocity = new Vector3(Random.Range(-10f, 10f), Random.Range(-10f, 10f), Random.Range(-10, 10f)); //give some twists and turns
bombRb.AddForce(ray.direction * throwForce, ForceMode.Impulse);
}
For destroying blocks (or anything really):
[PunRPC]
void DestroyObject(GameObject obj)
{
Destroy(obj);
}
BONUS QUESTION: How does one tackle particle effects with PUN? My effects just run once then destroy themselves, but I keep getting errors in the console saying that I shouldn’t destroy these objects without Photon Network. It doesn’t sound like a good idea to have 10s maybe 100s of effects with PhotonViews though…
Thanks in advanced for all the help by the way, I must’ve read dozens of your posts in these forums and they have been really helpful.