void Update() { if (EventSystem.current.IsPointerOverGameObject()) { return; } if (Input.GetMouseButtonDown(0)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, movementLayer)) { motor.MoveToPoint(hit.point); RemoveFocus(); } } if (Input.GetMouseButtonDown(1)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { _Interactable interactable = hit.collider.GetComponent <_Interactable> (); if (interactable != null) { SetFoucus(interactable); } } } }
void RemoveFocus() { if (focus != null) { focus.OnDefocused(); } focus = null; motor.StopFollowingTarget(); }
void SetFoucus(_Interactable newFocus) { if (newFocus != null) { if (focus != null) { focus.OnDefocused(); } focus = newFocus; motor.FollowTarget(newFocus); } focus.OnFocused(transform); }
public void StopFollowingTarget() { target = null; agent.stoppingDistance = 0f; agent.updateRotation = true; }
public void FollowTarget(_Interactable newTarget) { agent.stoppingDistance = 2f; agent.updateRotation = false; target = newTarget; }