So, I’ve clustered my mind and think it’s best I asked for help.
I’ve got the rough basics of multiplayer up, several players, etc.
Here’s the problem:
I have two switches that will be “activated” for five seconds after they are pressed. If both two are activated in the same room of time, a door will open.
How would I proceed in doing this? I thought I had gotten a grasp of RPC, but seemingly not.
Feel free to COMPLETELY disregard my script since I’m obviously not right at all, but here’s what I’ve tried most recently (leaving out variable declarations):
The player (All doors and switches have the “door” tag and have a DoCalls() on them)
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 10) Input.GetKeyDown("e")) {
if (hit.collider.tag == "door"){
hit.collider.networkView.RPC("DoCalls", RPCMode.All);
}
}
On the switch. DoCalls runs SwitchPressed so in my theory all players would get one variable added.
@RPC
function DoCalls(){
if (!switchDown){
print("Pressed");
switchDown = true;
targetDoor.networkView.RPC("SwitchPressed", RPCMode.All);
WaitForSeconds(5);
switchDown = false;
}
}
Script on the door to be opened (the ‘doomdoor’)
@RPC
function SwitchPressed(){
// This one is confusing, because seemingly when I press the button once, it gets run four times. i.e. //switchesPressed = 4 after one switch press
print("Running Switchadder");
switchesPressed++;
networkView.RPC("OpenDoor", RPCMode.All);
yield WaitForSeconds(5);
switchesPressed--;
}
@RPC
function DoCalls(){
if (switchesPressed == 2){
lDoor.animation.Play("door3_open_l");
rDoor.animation.Play("door3_open_r");
}
}