// Use this for initialization void Start() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit objectClicked; if (Physics.Raycast(ray, out objectClicked) && objectClicked.transform.tag != "Player") { Vector3 target = objectClicked.transform.tag == "Ground" ? objectClicked.point : objectClicked.transform.position; MoveTowardsDirection movement = gameObject.GetComponent <MoveTowardsDirection>(); movement.direction = MovementHelper.calculateNormalizedDirection(transform.position, target); } }
// Update is called once per frame void Update() { if (Input.GetMouseButton(1)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit objectClicked; if (Physics.Raycast(ray, out objectClicked) && objectClicked.transform.tag != "Player") { destination = objectClicked.point; destination.y = transform.position.y; _movement.direction = MovementHelper.calculateNormalizedDirection(transform.position, destination); } } if (Vector3.Distance(destination, transform.position) <= distanceTolerance) { _movement.direction = Vector3.zero; } }
// Update is called once per frame void Update() { _movement.direction = MovementHelper.calculateNormalizedDirection(transform.position, _target.transform.position); }