Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. public class MoveToMouseClick : MonoBehaviour {
  2.  
  3. public GameObject[] SendGoal;
  4. public LayerMask mask;
  5. public int mouse_button = 0;
  6.  
  7. // Update is called once per frame
  8. void Update () {
  9. if(Input.GetMouseButton(mouse_button))
  10. {
  11. RaycastHit hit;
  12. Ray r = Camera.main.ScreenPointToRay(Input.mousePosition);
  13. if(Physics.Raycast(r, out hit, 10000.0f, mask) == true)
  14. transform.position = hit.point;
  15.  
  16. foreach(GameObject go in SendGoal)
  17. {
  18. if(go != null && go.GetComponent<UnityEngine.AI.NavMeshAgent>() != null)
  19. {
  20. go.GetComponent<UnityEngine.AI.NavMeshAgent>().destination = transform.position;
  21. }
  22. }
  23. }
  24. }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement