// Update is called once per frame void FixedUpdate() { RaycastHit objHit; bool hit = Physics.Raycast(transform.position, transform.forward, out objHit); if (hit) { if (objHit.distance > interactionDistance) { NoticeObject("object is to far away to interact!"); return; } Interactive interaction = objHit.transform.gameObject.GetComponent <Interactive>(); if (interaction == null) { NoticeObject("object is not interactive!"); } else if (Input.GetMouseButtonDown(0)) { interaction.Interact(); } else { NoticeObject("Click to interact!"); } } else { Debug.Log("no ray hits!"); NotificationManager.inst.RemoveNotification(notifKey); } }
bool Interact() { Interactive[] interactive = FindObjectsOfType <Interactive>(); Interactive nearestWithInteraction = null; float nearestDistSq = ActivateDistance; foreach (Interactive candidate in interactive) { if (candidate.HasValidInteraction(this)) { Vector3 toCandidate = candidate.transform.position - transform.position; float distSq = toCandidate.sqrMagnitude; if (distSq < nearestDistSq) { nearestWithInteraction = candidate; nearestDistSq = distSq; } } } if (nearestWithInteraction) { nearestWithInteraction.Interact(this); return(true); } return(false); }
// Update is called once per frame void Update() { if (Input.GetKeyUp(triggerButton)) { target.Interact(); } }
public void BeforeHook() { if (beforeHook != null) { beforeHook.Interact(); } }
// Update is called once per frame void Update() { if (test) { Interactive interactive = GetComponent <Interactive>(); interactive.Interact(); test = false; } }
public void InteractWithTarget() { if (Input.GetButtonDown("Interact")) { if (focus != null) { focus.Interact(this); } } }
private IEnumerator Interact() { //_controls.Main.Interact.Disable(); print("You interacted!"); yield return(null); var waitTime = activeInteractive.Interact(this); DisableInteract(); yield return(waitTime); print("You can interact again."); _controls.Main.Interact.Enable(); }
/// <summary> /// /// </summary> /// <param name="playerInput"></param> /// <returns></returns> public override NewState InputHandle(PlayerInput playerInput) { if (Input.GetButtonDown(playerInput.up)) { if (interactiveObj != null) { interactiveObj.Interact(gameObject); } else { Debug.Log("No interactive object."); } } return(base.InputHandle(playerInput)); }
void UpdateInput() { controller.Jump(Input.GetButton("Jump")); float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); controller.Move(new Vector2(h, v)); if (Input.GetButtonDown("Fire2")) { if (interactive != null) { interactive.Interact(this); } } }
private IEnumerator PushBook() { _coroutineAllowed = false; _book.Interact(); _book.isActive = false; yield return(new WaitForSeconds(2)); _coroutineAllowed = true; _book.isActive = true; _statuePosition += 1; if (_statuePosition > 4) { _statuePosition = 1; } Pushed(name, _statuePosition); }
void Update() { Cursor.visible = false; if (!gameOver) { if (activeGun.isInputForShooting() && activeGun.HasBullets() && !activeGun.isReloading()) { activeGun.ManageShootBullets(); activeGun.UpdateBulletCount(); } if ((Input.GetKeyDown(ReloadKey) && !activeGun.isReloading() && !activeGun.IsFullyCharged()) || !activeGun.HasBullets()) { activeGun.Reload(); activeGun.UpdateBulletCount(); } if (Input.GetKeyDown(CarryFirstGunKey)) { activeGun.gameObject.SetActive(false); activeGun = guns [0]; activeGun.gameObject.SetActive(true); activeGun.UpdateBulletCount(); } if (Input.GetKeyDown(CarrySecondGunKey)) { activeGun.gameObject.SetActive(false); activeGun = guns [1]; activeGun.gameObject.SetActive(true); activeGun.UpdateBulletCount(); } if (Input.GetKeyDown(InteractKey) && HasInteractiveObject()) { interactiveObject.Interact(); } } }
public override void HandleInput() { if (stateMachine.inputManager.actionInteract.triggered) { Interactive interactive = interactiveIdentifier.PeekMostRelevantInteractive(); if (interactive != null) { System.Type interactiveType = interactive.GetType(); if (interactiveType == typeof(LiftableObject)) { interactiveIdentifier.PopMostrelevantInteractive(); interactive.Interact(); objectManipulator.LiftObject(interactive.gameObject); base.stateMachine.ChangeState(typeof(PlayerLiftingState)); } else if (interactiveType.IsSubclassOf(typeof(Activator)) && interactiveType != typeof(GroundButton) && !interactive.CompareTag("Receptor")) { interactive.Interact(); } else if (interactiveType == typeof(PushableObject)) { interactive.Interact(); objectManipulator.GrabObject(interactive.gameObject); base.stateMachine.ChangeState(typeof(PlayerDraggingState)); interactiveIdentifier.SetInteractPopupShowState(false); } else if (interactiveType == typeof(InteractiveDoor) || interactiveType == typeof(ItemContainer) || interactiveType == typeof(Guardian)) { interactive.Interact(transform.parent.gameObject); interactiveIdentifier.SetInteractPopupShowState(false); interactiveIdentifier.PopMostrelevantInteractive(); } else if (interactiveType == typeof(InteractiveShield)) { interactive.Interact(transform.parent.gameObject); interactiveIdentifier.SetInteractPopupShowState(false); } } } else if (stateMachine.inputManager.actionAttack1.triggered) { if (holdAttackCheckCoroutine == null) { holdAttackCheckCoroutine = StartCoroutine(CheckForAttackHoldInput()); } else { StopCoroutine(holdAttackCheckCoroutine); holdAttackCheckCoroutine = StartCoroutine(CheckForAttackHoldInput()); } stateMachine.inputManager.actionAttack1.canceled += StopCheckForAttackHoldInputCoroutine; } else if (stateMachine.inputManager.actionDefend.triggered && canDefend) { stateMachine.ChangeState(typeof(PlayerDefendingState)); } }