Make trigger event can be observe in multi player (photon)?
Hi everyone,
I have two scene with 2 players and I use photon to establish the networking to allow them to connected with each other.
In the scenes, I have a OnTriggerExit script and it works perfectly in my scene(single user case). Can the other player see the event happen? Or I need to write something different to make it works?
My script in the scene:
public class Exit : MonoBehaviour
{ public GameObject Canvasinstruction;
private void OnTriggerExit() //when player exit sth
{
Canvasinstruction.SetActive(true);
} //some object appear
}
Answer by ChristianSimon · Mar 15, 2018 at 10:29 AM
Hi,
OnTriggerExit will be called on all clients who are detecting this event in their own simulation. If you have Client A who detects this event, OnTriggerExit will be called for him. However if Client B doesn't detect this event, OnTriggerExit isn't called for him.
Answer by ngkenneth · Mar 15, 2018 at 10:41 AM
@ChristianSimon Can client B observe client A's event ? That's what I want to achieve.
Thanks a lot!
If both clients are running different simulations (for example different scenes), one client have to explicitly tell the other client.
Do you mean I should do sth like:
add a tag to the client A and if client A Exit the trigger object, the event will trigger?
Sorry for a lot of questions and Thanks again!
No, if Client A runs a different simulation than Client B, Client A has to notify Client B with a network message. This can be for example done by using the RaiseEvent function. You can use this to let the other client know, that a client has performed any kind of action (for example OnTriggerExit has been called). Then the client who received this message can do something related to it, for example enabling a certain Canvas. You can read about the RaiseEvent function in the RPCs and RaiseEvent documentation page.
Your answer
![](https://koobas.hobune.stream/wayback/20220612154551im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
What's wrong with my script ? 0 Answers
Unity Photon Player Instantiation 1 Answer
Photon RPC Parameter NullReferenceException 1 Answer
Sync Mecanim Trigger over network 1 Answer
I get an error message every time i run this script? Any ideas? 0 Answers