Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Update() {
- CmdInteract();
- }
- [Command]
- private void CmdInteract() {
- // Hide interact box
- RpcSetInteract(false);
- // We are looking at something
- if (Physics.Raycast(Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)), out RaycastHit hit, InteractDistance)) {
- // Interact
- Interact(hit.collider.gameObject);
- }
- }
- [Server]
- private void Interact(GameObject interactObject) {
- // Get IInteractable
- IInteractable interactable = interactObject.GetComponent<IInteractable>();
- // Has IInteractable
- if (interactable != null) {
- // His empty
- if (!string.IsNullOrEmpty(interactable.GetInteractText())) {
- // Show interact box
- RpcSetInteract(true);
- // Set text
- InteractText.SetText(interactable.GetInteractText().Replace("%KEY%", "F"));
- }
- // Player interact
- if (Input.GetButtonDown(InteractKey)) { Debug.Log(gameObject.name + "INTERACT"); interactable.OnInteract(Controller); }
- }
- }
- [ClientRpc]
- private void RpcSetInteract(bool state) {
- InteractBox.enabled = InteractText.enabled = state;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement