private void OnTriggerStay(Collider other) { if (other.tag == "Ground" || other.tag == "Player" || _grabing != null) { return; } // Debug.Log("Colidded with: " + other.ToString()); if (other.tag == "Pickable") { if (Input.GetKeyDown(KeyCode.E)) { Take(other.gameObject); } } if (other.tag == "Shelf") { if (Input.GetKeyDown(KeyCode.Q)) { IActionable actionable = other.GetComponent(typeof(IActionable)) as IActionable; actionable.Action(); } } }
public void OnAction() { if (closestInteractableObject != null) { IActionable actionableComponent = closestInteractableObject.GetComponent <IActionable>(); actionableComponent.Action(); } }
private void UseAction() { IActionable actionable = itemInstance.GetComponent <IActionable>() as IActionable; if (actionable != null) { if (actionable.Action()) { anim.Play("shoot"); } } }
void Update() { float moveX = Input.GetAxis("Horizontal"); PlayerOrientation(moveX); rb.MovePosition(rb.position + Vector2.right * moveX * speed * Time.deltaTime); if (Input.GetKeyDown(KeyCode.Space)) { rb.AddForce(Vector2.up * 8000); } if (Input.GetKeyDown(KeyCode.F) && currentActionable != null) { Debug.Log("current != null"); IActionable actionable = currentActionable.GetComponent <IActionable>(); if (actionable != null) { Debug.Log("actionable.Action()"); actionable.Action(); } } }
void Update() { bool highlight = false; bool outline = false; bool select = false; hitGo = null; if (CastRay()) { HandleKeys(); hitGo = raycast.hit.collider.gameObject; ctx.raycast = raycast; switch (hitGo.tag) { case "Surface": highlight = true; break; case "Selectable": highlight = true; outline = true; // print(string.Format("frame counts: {0} - {1}", tsTouchEvent.frameCount, Time.frameCount)); if (tsTouchEvent.frameCount == Time.frameCount - 1) { select = true; ctx.tsTouchEvent = tsTouchEvent; } else { ctx.tsTouchEvent = null; } break; } } if (highlight) { ShowHighlighter(raycast.hit.point); } else { HideHighlighter(); } if (outline) { SetOutlined(hitGo); } else { ClearOutlined(); } if (select) { IActionable actionable = (IActionable)hitGo.GetComponent(typeof(IActionable)); print(string.Format("Selected object! {0} -- {1}", hitGo.name, actionable)); if (actionable != null) { actionable.Action(ctx); } ctx.previousSelections.Enqueue(new TimestampedSelection(Time.time, Time.frameCount, hitGo)); } }