Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class door : MonoBehaviour {
- public bool open;
- private float _timeout;
- public float Timeout;
- public Transform player;
- public float MaxDistance = 3;
- // Use this for initialization
- void Start ()
- {
- player = GameObject.FindGameObjectWithTag("Player").transform;
- }
- // Update is called once per frame
- void Update ()
- {
- _timeout += Time.deltaTime;
- if(Input.GetKey(KeyCode.E)&&_timeout>Timeout&&Vector3.Distance(transform.position, player.transform.position)<MaxDistance)
- {
- networkView.RPC("Door",RPCMode.Server);
- }
- }
- [RPC]
- void Door () {
- networkView.RPC("Client_OpenDoor",RPCMode.All);
- }
- [RPC]
- void Client_OpenDoor () {
- _timeout = 0;
- open = !open;
- if(open == true)
- {
- transform.animation.CrossFade("open");
- Debug.Log("LOG: open door");
- }
- if(open == false)
- {
- transform.animation.CrossFade("close");
- Debug.Log("LOG: close door");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement