void Update() { Vector3 lookDir = Vector3.up * Input.GetAxis("Vertical"); if (lookDir.y != 0) { LookingUp = lookDir.y >= 0; SetClosest(); } if (Input.GetKeyDown(KeyCode.Alpha2)) { interacting = true; } else if (Input.GetKeyUp(KeyCode.Alpha2)) { interacting = false; } if (interacting && currentClosest != null) { gameObject.transform.parent.gameObject.GetComponent <Animator>().Play("Player-Cast"); currentClosest.Interact(new MobileInput(InputTypes.PlantInteract, Vector3.zero)); if (!currentClosest.Active) { inRangeInteractables.Remove(currentClosest); currentClosest.Dehighlight(); currentClosest = null; SetClosest(); } } }
public override void DoInteractorCasterHit(CharacterActor characterActor, Direction direction, RaycastHit2D hit, Collider2D collider) { Interactable interactable = collider.GetComponentInParent <Interactable>(); if (interactable) { switch (direction) { case Direction.Up: interactable.Interact(Direction.Down, characterActor.thisGameObject); break; case Direction.Down: interactable.Interact(Direction.Up, characterActor.thisGameObject); break; case Direction.Left: interactable.Interact(Direction.Right, characterActor.thisGameObject); break; case Direction.Right: interactable.Interact(Direction.Left, characterActor.thisGameObject); break; } } }
void HandleInteraction(Interactable interactable) { KeyCode key = KeyCode.E; switch (interactable.interactionType) { case Interactable.InteractionType.Click: if (Input.GetKeyDown(key)) { interactable.Interact(); } break; case Interactable.InteractionType.Hold: if (Input.GetKey(key)) { interactable.Interact(); } break; case Interactable.InteractionType.Minigame: break; default: throw new System.Exception("Unsupported type of interactable."); } }
public void InteractWithObject(Interactable interactable) { switch (interactable) { case DeadBody D: //checks on player to see if interaction is valid { if (heldInteractable != null) { Debug.Log("Need to let go first: " + D.gameObject); return; } Debug.Log("Interact deadbody: " + D.gameObject); heldInteractable = D; //transform.LookAt(D.transform); interactable.Interact(gameObject); iScanner.RemoveInteractableFromList(heldInteractable); player.DraggingBody = true; break; } case Container C: //checks on player to see if interaction is valid { if (C.ObjectInside != null) { Debug.Log("Container is full"); return; } else if (heldInteractable != null) { heldInteractable.Interact(gameObject); interactable.Interact(heldInteractable.gameObject); heldInteractable = null; player.DraggingBody = false; } else { Debug.Log("Entering " + C.gameObject); GetComponent <CharacterController>().enabled = false; interactable.Interact(gameObject); player.Hiding = true; interactedBarrel = interactable; } break; } case BloodSuckTarget B: //see if the object itself can validate interaction { interactable.Interact(gameObject); heldInteractable = B; transform.LookAt(interactable.transform); break; } default: break; } }
public void Interact() { // Interact with the interactable closest to us if (closestInteractable != null && input.PlayerActionsEnabled) { closestInteractable.Interact(gameObject); closestInteractable = null; } }
public void Pickup() { if (isInteracting && interactable.interactableType == InteractableType.DroppedItem) { animator.SetTrigger("tr_pickup"); interactable.Interact(); interactable.CloseInfo(); isInteracting = false; } }
private void Update() { if (interactPermit && !isIteracting) { if (Input.GetKeyDown(KeyCode.F)) { isIteracting = true; } currentInteractable.Interact(); } }
// NOTE: It is important that this happens in FixedUpdate, because it needs // to be in sync with LightAngler. void FixedUpdate() { if (numObjectsPressing > 0) { controled.Interact(interactionDirection); } else { controled.Interact(-interactionDirection); } }
public override IEnumerator Behavior() { if (interactable == null) { yield break; } if (wait) { yield return(StartCoroutine(interactable.Interact(this))); yield break; } StartCoroutine(interactable.Interact(this)); }
// Update is called once per frame void Update() { Vector2 position = rigidbody2D.position; float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); Vector2 move = new Vector2(horizontal, vertical); position = position + move * speed * Time.deltaTime; rigidbody2D.MovePosition(position); if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f)) { lookDirection.Set(move.x, move.y); lookDirection.Normalize(); } animator.SetFloat("Look X", lookDirection.x); animator.SetFloat("Look Y", lookDirection.y); animator.SetFloat("Speed", move.magnitude); if (Input.GetKeyDown(KeyCode.Z)) { RaycastHit2D hit = Physics2D.Raycast(rigidbody2D.position + Vector2.up * 1.0f, lookDirection, 1.0f, LayerMask.GetMask("Interactables")); if (hit.collider != null) { Interactable interactable = hit.collider.GetComponent <Interactable>(); if (interactable != null) { interactable.Interact(); } } } }
public void Interact() { // if ( interactables != null ) { // Point player = GameController.GetInstance().GetPlayer(); // // for ( int i = 0; i < interactables.Length; i++ ) { // if ( interactables[i].InRange( player ) ) { // interacted = interactables[i]; // break; // } // } // } foreach (KeyValuePair <Point, Interactable> pair in Interactables) { Point player = GameController.Instance().GetPlayer(); if (player != null) { Point pos = pair.Key; Interactable inter = pair.Value; if (player.Equals(pos) || (inter.ActiveInRange == true && pos.IsNeighbour(player))) { inter.Interact(); } } } }
private void FixedUpdate() { #region Interactable Region Ray ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2)); RaycastHit hit; if (Physics.Raycast(ray, out hit, 2)) { Interactable interactable = hit.collider.GetComponent <Interactable>(); if (interactable != null) { if (!interactable.canvas.gameObject.activeInHierarchy) { StartCoroutine(interactable.DisplayInfo(true, 1f)); } if (Input.GetKeyDown(KeyCode.E)) { Cursor.lockState = CursorLockMode.None; FocusOnObject(hit.transform, 10); interactable.Interact(); } } } #endregion }
protected void Update() { if (EventSystem.current.IsPointerOverGameObject()) { return; } if (Input.GetMouseButtonDown(0)) { inputMousePos = Input.mousePosition; clickPosFar.x = inputMousePos.x; clickPosFar.y = inputMousePos.y; clickPosNear.x = inputMousePos.x; clickPosNear.y = inputMousePos.y; worldPointFar = cam.ScreenToWorldPoint(clickPosFar); worldPointNear = cam.ScreenToWorldPoint(clickPosNear); Debug.DrawRay(worldPointFar, worldPointFar - worldPointNear, Color.green); if (Physics.Raycast(worldPointNear, worldPointFar - worldPointNear, out hitObject, maxCheckDistance, layerMask)) { hitInteractable = hitObject.collider.GetComponent <Interactable>(); if (hitInteractable != null) { if ((transform.position - hitInteractable.transform.position).magnitude < hitInteractable.interactionRadius) { hitInteractable.Interact(); hitInteractable = null; } } } } }
void Update() { if (isTouchingInteractable && player.player_Input.IsKeyPressed(interactableRef.GetInputKey())) { interactableRef.Interact(player); } }
private void OnUseButton(bool isDown) { if (!isDown) { return; } if (miniGame.enabled) { miniGame.ReceiveInput(false); return; } // Grab / Drop Interactable hoveredInteractable = hovered; if (hoveredInteractable != null) { if (holded != null) { hoveredInteractable.InteractWithItem(holded); } else { hoveredInteractable.Interact(this); } } }
private void Interact() { if (rightHandEmpty) { RaycastHit hit; Physics.Raycast(camera.transform.position, camera.transform.forward, out hit, 10); if (hit.transform != null) { Interactable hitItem = hit.transform.gameObject.GetComponent <Interactable>(); Debug.Log("hitItem = " + hitItem); if (hitItem != null) { hitItem.Interact(); if (hitItem.isHoldItem) { rightHandEmpty = false; } } } } else { GameObject child = rh.transform.GetChild(0).gameObject; Rigidbody rb = child.GetComponent <Rigidbody>(); rb.AddForce(camera.transform.forward * 15, ForceMode.Impulse); child.transform.parent = null; rightHandEmpty = true; } }
private void Update() { if (focus != null && input.interactInput) { focus.Interact(); } }
// Update is called once per frame private void Update() { if (currentItem != null) { inRange = Vector3.Distance(currentItem.transform.position, GameManager.instance.GetPlayer().transform.position) < interactionRange; } else { inRange = false; } if (inRange || interactionText == "") { itemInteractionText.text = interactionText; } else { itemInteractionText.text = "OUT OF RANGE"; } if (Input.GetMouseButtonUp(0) && inRange) { if (currentItem != null) { currentItem.Interact(); } } }
public void DoInteract() { if (targetFocus) { targetFocus.Interact(); } }
// Update is called once per frame void Update() { if (transform.position != Position) { // Check only after moving Position = transform.position; float Range = -1; Interactable NewTarget = null; foreach (Interactable i in Interactables) { float TempRange = (i.Position() - Position).magnitude; if (TempRange < Range || Range == -1) { Range = TempRange; NewTarget = i; } } Target = NewTarget; if (Target) { Retarget(); } } if (Input.GetButtonDown("Interact") && Target != null) { Target.Interact(Plr); } }
// Update is called once per frame void Update() { if (targetInteractable != null && Input.GetKeyDown(KeyCode.E)) { targetInteractable.Interact(); } }
// Update is called once per frame void Update() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, maxDistance)) { Interactable interactable = hit.transform.GetComponent <Interactable>(); if (interactable != null) { interactionText.text = interactable.GetInteractionText(); interactionText.gameObject.SetActive(true); if (Input.GetKeyDown(KeyCode.E)) { interactable.Interact(); } } } else { if (interactionText.gameObject.activeSelf) { interactionText.gameObject.SetActive(false); } } }
// This is called when the nav mesh agent is very close to it's destination. private void Stopping(out float speed) { // Stop the nav mesh agent from moving the player. agent.isStopped = true; // Set the player's position to the destination. transform.position = destinationPosition; // Set the speed (which is what the animator will use) to zero. speed = 0f; // If the player is stopping at an interactable... if (currentInteractable) { // ... set the player's rotation to match the interactionLocation's. transform.rotation = currentInteractable.interactionLocation.rotation; // Interact with the interactable and then null it out so this interaction only happens once. currentInteractable.Interact(); currentInteractable = null; // Start the WaitForInteraction coroutine so that input is ignored briefly. StartCoroutine(WaitForInteraction()); } }
// Called when the player tries to interact with something from the input system. private void OnInteract() { if (currentInteract != null) { currentInteract.Interact(); } }
void Update() { if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.A)) { if (!m_animator.GetCurrentAnimatorStateInfo(0).IsName("Walk")) { m_animator.Play("Walk"); } } else { if (!m_animator.GetCurrentAnimatorStateInfo(0).IsName("Idle")) { m_animator.Play("Idle"); m_walkIndex = 0; } } if (Input.GetKeyDown(KeyCode.F)) { if (m_currentInteractable != null) { m_currentInteractable.Interact(); SFXManager.Instance.PlaySound(m_interact); } } }
void Interact(Interactable target) { // do some stupid thing with things that are connected Item returnedItem = target.Interact(heldItem); if (!returnedItem) { RemoveItem(); //item was taken, nothing returned } else if (returnedItem == heldItem) { //item was not taken } else if (returnedItem != heldItem) { //item was taken and new item given if (heldItem) { RemoveItem(); } AddItem(returnedItem); } }
private void Update() { if (!_canInteract) { return; } Ray ray = new Ray(transform.position, transform.forward); RaycastHit[] hits = Physics.RaycastAll(ray, 1.25f); interactiveTextObject.SetActive(false); foreach (RaycastHit hit in hits) { Interactable interactable = hit.transform.GetComponent <Interactable>(); if (interactable != null && interactable.canInteract) { interactiveTextObject.SetActive(true); interactiveText.text = interactable.description; if (Input.GetMouseButtonDown(0)) { interactable.Interact(); } break; } } }
private bool interact() { Vector2 start = transform.position; Vector2 end = start + getInteractDirection() * interactDistance; int layerMask = 1 << interactableLayerMask; RaycastHit2D[] hitObjects = Physics2D.LinecastAll(start, end, layerMask); if (hitObjects.Length > 0) { // Get all objects in front of the player with the layerMask foreach (RaycastHit2D hit in hitObjects) { // Get the first hit object in the list which has an Interactable script and interact with it Interactable hitInteractable = hit.transform.GetComponent <Interactable>(); if (hitInteractable) { hitInteractable.Interact(); return(true); } } } return(false); }
void OnMouseUp() { if (interactable != null && interactable.enabled) { interactable.Interact(); } }
public void OnPointerUp(PointerEventData eventData) { bool itemsSuccessfulyUsedForInteraction = false; Interactable interactable = Interactable.GetInteractableAtMousePosition(); if (interactable) { ItemSlot itemSlot = eventData.pointerPress.GetComponentInChildren <ItemSlot>();//pointerPress vs pointerDrag? if (itemSlot && itemSlot.Item) { itemsSuccessfulyUsedForInteraction = interactable.Interact(itemSlot.Item); } } if (itemsSuccessfulyUsedForInteraction && Item.DestroyOnSuccessfulUse) { RemoveItem(); } StopDragItem(); if (Item) { _imageElementForItem.enabled = true; } }
public void ClickAndInteract() { ClearNav(); if (canClick) { //clear previous data Ray ray = new Ray(camOrigin.position, camOrigin.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, PointingLayers)) { //check that the target is interactable if (hit.collider.gameObject.GetComponent<Interactable>()) { interactionTarget = hit.transform.GetComponent<Interactable>(); Vector3 nearestSpot = interactionTarget.NearestSpot(movedChar.transform); //see if the character is close enough. If too far, approach the target and set an interaction to trigger if (Vector3.Distance(movedChar.transform.position, nearestSpot) <= interactionDistance) { interactionTarget.Interact(); lookIK.SetIKTarget(interactionTarget.transform.position); } else { //walk to the target and then interact with it approachingTarget = true; SetPath(nearestSpot); lookIK.SetIKTarget(interactionTarget.transform.position); } } else { //indicator that nothing there can be interacted with //some sort of dialogue like "it's nothing special" } } } }