- Home /
Question by
GroundstompStudios · Apr 30, 2020 at 02:44 AM ·
c#multiplayerphotonontriggerentermultiplayer-networking
How To Destroy An Object Server Side When Using OnTriggerEnter
I am currently making a multiplayer game and I want the pickups to get destroyed once one of the players have picked it up. Here is my code
private void OnTriggerEnter(Collider collision)
{
if (collision.CompareTag("Shield"))
{
if (stats.currentShield == stats.maxShield)
{
StartCoroutine(FullShield());
//Debug.Log("You have full shield!");
}
else if (stats.currentShield < stats.maxShield)
{
FindObjectOfType<AudioManager>().Play("ShieldPickup");
Destroy(collision.gameObject); // cant figure out how to destroy this server side (it has a photon view)
stats.currentShield += 5f;
shieldBar.SetShield(stats.currentShield);
}
}
if (collision.CompareTag("Health"))
{
if (stats.currentHealth == 100f)
{
StartCoroutine(FullHealth());
//Debug.Log("You have full HP!");
}
else if (stats.currentHealth < 100f)
{
FindObjectOfType<AudioManager>().Play("HealthPickup");
Destroy(collision.gameObject); // // cant figure out how to destroy this server side (it has a photon view)
stats.currentHealth += 5f;
healthBar.SetHealth(stats.currentHealth);
}
}
}
Comment
Best Answer
Answer by GetLitGames · Apr 30, 2020 at 01:54 PM
Pretty sure Photon has the concept of ownership, so you would need to send a message to the owner to tell him to destroy the item. You may have to make a remote procedure call to the owner's machine to have them destroy it.
Here is a good Photon resource that summarizes a bunch of Photon's functionality in one place: https://gist.github.com/ssshake/86b4da6c31258a7188f7fef3dbaf1d26
If you scroll to the section on Scene Objects it shows an example of sending an RPC to pickup an item by passing the item's ViewId.