// Use this for initialization void Start() { GameObject[] targets = GameObject.FindGameObjectsWithTag("Player"); if (targets.Length > 0) { _target = targets[0]; } _movement = gameObject.GetComponent <MoveTowardsDirection>(); }
// 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); } }
public void StopMovement(GameObject target) { MoveTowardsDirection movement = target.GetComponent <MoveTowardsDirection>(); if (movement) { movement.direction = Vector3.zero; } else { Debug.LogError("Target must have component MoveTowardsDirection to Stop Movement", target); } }
// Use this for initialization void Start() { destination = transform.position; _movement = gameObject.GetComponent <MoveTowardsDirection>(); }