public void FollowTarget(Intearactable newTarget) { agent.stoppingDistance = newTarget.radius * .8f; agent.updateRotation = false; target = newTarget.interactionTransform; }
// Update is called once per frame void Update() { if (Input.GetMouseButton(0)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, movementMask)) { motor.MoveToPoint(hit.point); RemoveFocus(); } } if (Input.GetMouseButton(1)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { Intearactable interactable = hit.collider.GetComponent <Intearactable>(); if (interactable != null) { SetFocus(interactable); } } } }
void RemoveFocus() { if (focus != null) { focus.OnDefocused(); } focus = null; motor.StopFollowingTarget(); }
void SetFocus(Intearactable newFocus) { if (newFocus != focus) { if (focus != null) { focus.OnDefocused(); } focus = newFocus; motor.FollowTarget(newFocus); } newFocus.OnFocused(transform); }