please help, im trying to open doors across the network what am i doing wrong !

Options
Please help, the door does open but only on the client camera
what am i doing wrong ? this is the script


using UnityEngine;
using Photon.Pun;

[RequireComponent(typeof(PhotonView))]
[RequireComponent(typeof(PhotonAnimatorView))]


public class OpenableDoor : MonoBehaviourPun
{
//PhotonView photonView = PhotonView.Get(this);

// Smoothly open a door
public float doorOpenAngle = 90.0f; //Set either positive or negative number to open the door inwards or outwards
public float openSpeed = 2.0f; //Increasing this value will make the door open faster

bool open = false;
bool enter = false;

float defaultRotationAngle;
float currentRotationAngle;
float openTime = 0;
[PunRPC]
void Start()
{
defaultRotationAngle = transform.localEulerAngles.y;
currentRotationAngle = transform.localEulerAngles.y;
}

// Main function
[PunRPC]
void Update()
{
if (openTime < 1)
{
openTime += Time.deltaTime * openSpeed;
}
transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, Mathf.LerpAngle(currentRotationAngle, defaultRotationAngle + (open ? doorOpenAngle : 0), openTime), transform.localEulerAngles.z);

if (ControlFreak2.CF2Input.GetKeyDown(KeyCode.F) && enter)
{

open = !open;
currentRotationAngle = transform.localEulerAngles.y;
openTime = 0;
}
}

// Display a simple info message when player is inside the trigger area
[PunRPC]
void OnGUI()
{
if (enter)
{
GUI.Label(new Rect(Screen.width / 2 - 75, Screen.height - 100, 150, 30), "Press 'F' to open the door");
}
}

// Activate the Main function when Player enter the trigger area
[PunRPC]
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
enter = true;

}
{
photonView.RPC("openDoor", RpcTarget.All, null);
}
}

// Deactivate the Main function when Player exit the trigger area
[PunRPC]
void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
enter = false;
}
}
}

Best Answer

  • RoyKent
    RoyKent
    Answer ✓
    Options
    or at least if there any simple script for doors opening and closing i already made the animation (openDoor, closeDoor) and ready to be droped in the animator, thank you

Answers

  • RoyKent
    RoyKent
    Answer ✓
    Options
    or at least if there any simple script for doors opening and closing i already made the animation (openDoor, closeDoor) and ready to be droped in the animator, thank you