void interactWith(BaseClasses.Watchable toInteractWith) { if (!toInteractWith.isNull()) { Abstracts.Interactable[] components = toInteractWith.gameObject.GetComponents <Abstracts.Interactable>(); foreach (Abstracts.Interactable component in components) { if (component.IsWithinRange(transform.parent.gameObject)) { if (Input.GetButtonDown("Interact")) { component.OnInteractionEnter(); } if (Input.GetButton("Interact")) { component.OnInteractionStay(); } if (Input.GetButtonUp("Interact")) { component.OnInteractionExit(); } } } } }
bool LookAtStay(BaseClasses.Watchable toInteractWith) { if (!toInteractWith.isNull()) { Abstracts.Interactable[] components = toInteractWith.gameObject.GetComponents <Abstracts.Interactable>(); foreach (Abstracts.Interactable component in components) { if (component.IsWithinRange(transform.parent.gameObject)) { component.OnWatchStay(); crosshair.highlight = true; return(true); } } } crosshair.highlight = false; return(false); }
void See() { target = LookingAt(); if (target != null) { if (lastTarget != null) { if (target.isNull() && !lastTarget.isNull()) { LookAtExit(lastTarget); lastTarget = null; } } if (LookAtStay(target)) { if (lastTarget != null) { if (target.gameObject != lastTarget.gameObject) { LookAtEnter(target); LookAtExit(lastTarget); lastTarget = target; } } else { LookAtEnter(target); lastTarget = target; } } interactWith(target); } else { if (lastTarget != null) { LookAtExit(lastTarget); lastTarget = null; } } }