How to use triggers with PUN?

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How to use triggers with PUN?

Laplace
2020-09-03 14:37:52

I've been going at this for 3 days but I can't find any tutorial of how to get triggers working. I'm making a simple game, I've managed to get the players to join a room. I place a trigger and an AI has to go to its position. The AI interacts with the trigger alright but the player cannot interact with it. Both the trigger and AI are running on local machine.

Comments

OdoVR
2020-09-24 00:43:38

Are you talking about handling an OnTrigger() event?

If so, you can run a check to see if the owner of the "other" collider is your local player (photonView.isMine) and handle the event as you need.

For example:

private void OnTriggerEnter(Collider other)
{
PhotonView phView = other.gameObject.GetComponent();

if (!phView.IsMine)  
{  
    // Not our local player - ignore  
    return;  
}

// Handle your event here  

}

Hope this helps. :-)

Back to top