Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. private void Update() {
  2.  
  3.         CmdInteract();
  4.  
  5.     }
  6.  
  7.     [Command]
  8.     private void CmdInteract() {
  9.  
  10.         // Hide interact box
  11.         RpcSetInteract(false);
  12.  
  13.         // We are looking at something
  14.         if (Physics.Raycast(Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)), out RaycastHit hit, InteractDistance)) {
  15.  
  16.             // Interact
  17.             Interact(hit.collider.gameObject);
  18.  
  19.         }
  20.  
  21.     }
  22.  
  23.  
  24.     [Server]
  25.     private void Interact(GameObject interactObject) {
  26.  
  27.         // Get IInteractable
  28.         IInteractable interactable = interactObject.GetComponent<IInteractable>();
  29.  
  30.         // Has IInteractable
  31.         if (interactable != null) {
  32.  
  33.             // His empty
  34.             if (!string.IsNullOrEmpty(interactable.GetInteractText())) {
  35.  
  36.                 // Show interact box
  37.                 RpcSetInteract(true);
  38.  
  39.                 // Set text
  40.                 InteractText.SetText(interactable.GetInteractText().Replace("%KEY%", "F"));
  41.  
  42.             }
  43.  
  44.             // Player interact
  45.             if (Input.GetButtonDown(InteractKey)) { Debug.Log(gameObject.name + "INTERACT"); interactable.OnInteract(Controller); }
  46.  
  47.         }
  48.  
  49.     }
  50.  
  51.     [ClientRpc]
  52.     private void RpcSetInteract(bool state) {
  53.         InteractBox.enabled = InteractText.enabled = state;
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement