static float AngleOfInteraction(InteractionDetails i) { Vector3 direction = (i.center.position - PlayerStatus.thePlayer.transform.position); float angle = Quaternion.Angle(PlayerStatus.thePlayer.transform.rotation, Quaternion.FromToRotation(Vector3.up, new Vector3(direction.x, direction.y, 0))); return(angle); }
private void Update() { if (Time.time > nextCheck) { var nearby = possibleInteractions.Where(x => (x.center.position - PlayerStatus.thePlayer.transform.position).magnitude < interactRadius); nearby = nearby.OrderBy(x => AngleOfInteraction(x)); currentInteraction = null; if (nearby.Count() > 0) { var best = nearby.First(); if (AngleOfInteraction(best) < 90) { currentInteraction = best; } } nextCheck = Time.time + .2f; } if (currentInteraction != null) { interactText.text = "press 'e' to " + currentInteraction.text; interactionMarker.transform.position = currentInteraction.center.position; interactionMarker.transform.localScale = new Vector3(currentInteraction.sizeOfRect, currentInteraction.sizeOfRect, 1f); interactionMarker.SetActive(true); if (Time.timeScale > 0.1f && Input.GetKey(KeyCode.E)) { currentInteraction.callback(); } } else { interactText.text = ""; interactionMarker.SetActive(false); } }