How to get OnTriggerEnter working over a network
Hi I was wondering if anyone could help me please. I am working on my first networked game. I have an object that with the OnTriggerEnter void on it. When I enter the trigger radius - the debug.log message is not appearing on the console, clearly suggesting I am missing something.
If anyone can help it is greatly appreciated. Here is my code. The object in question has a rigidbody and is Kinematic. The IsTrigger box is ticked and it also has a Network View component attached to it.
The RPC stuff that uses the spacebar works fine. I'm just not sure how to use OnTriggerEnter when using a network.
void Update () {
if(!networkView.isMine){
return;
}
if(Input.GetKeyDown(KeyCode.Space)){
networkView.RPC("test", RPCMode.All);
}
}
void OnTrigggerEnter(Collider other) {
networkView.RPC("test", RPCMode.AllBuffered);
print("hello");
}
[RPC]
void test (NetworkMessageInfo info){
Debug.Log("Test " + info.sender.ipAddress);
}
Answer by Kebabs · Nov 21, 2014 at 10:29 PM
I cant believe this. haha please excuse my humanity here - i had trigggerEnter instead of triggerEnter. Its all working fine now.
Answer by Owen-Reynolds · Nov 21, 2014 at 09:16 PM
Looks like a standard trigger problem to me. Are you saying the "hello" doesn't even fire?
Don't think OnTriggerEnter works "over a network" (what would that even mean?) and doesn't need to. It just checks for things on this machine. Suppose computer B sees player 2 move into a trigger. Maybe player 2 was spawned using Network.Instantiate. Maybe it's only moving because of automatic mirroring, using the network. Those are boring details to computer B. Player 2 still moved into the trigger, just like anything else.
The hello line doesn't come up. What I ultimately wanted to do was to have a switch which when the player pressed E - the switch would activate and move something else. This is reason why I was using OnTriggerEnter. I was assu$$anonymous$$g that it would work online too.
Your answer
Follow this Question
Related Questions
Simple NetworkView Question. 1 Answer
[UNET] Client cannot call [Command]s, only the host can 1 Answer
Network Soccer Ball Position jitter, sending transform position late? 0 Answers
UNET AssetID 0000 zero 0 Answers
PLS recommend plugins for networking/sever which ONLY work for authentication + storing player info. 0 Answers