I have a script saying that if the player presses a button while in a certain trigger it commands the server to open the door. My player is the local player because I get the debug message kick (see the script) so I really don’t understand what the problem is.
Here is the script for the player :
private void OnTriggerStay2D(Collider2D other)
{
if (other.tag == "Door")
{
Door door = other.GetComponent<Door>();
if (door.closed)
{
if (Input.GetButtonDown("Kick") && isLocalPlayer)
{
Debug.Log("kick");
door.CmdOpenDoor(transform.position.x);
}
if (input.rawPeek > 0)
{
peek(door.GetPeekPos(transform.position.x), transform.position.x > door.transform.position.x);
}
if (input.rawPeek < 1 && peeking)
{
stopPeek();
}
}
if (!door.closed && peeking) {
stopPeek();
}
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.tag == "Door")
{
other.GetComponent<Door>().CmdClose();
if (peeking)
{
stopPeek();
}
}
}
}
Here is the script for the door :
[Command]
public void CmdOpenDoor(float x){
if (x < doors[0].transform.position.x) {
RpcOpen(RIGHT);
}
if (x > doors[0].transform.position.x) {
RpcOpen(LEFT);
}
}
[Command]
public void CmdClose()
{
RpcClose();
}
[ClientRpc]
private void RpcOpen (int i) {
closed = false;
doors[0].enabled = false;
closedCollider.enabled = false;
viewCollider.enabled = false;
doors*.enabled = true;*
}
[ClientRpc]
public void RpcClose () {
if (closed == false)
{
closed = true;
doors[0].enabled = true;
closedCollider.enabled = true;
viewCollider.enabled = true;
doors.enabled = false;
doors.enabled = false;
}
}
Please help !!