Advertisement
Romanz7410

My Code

Mar 28th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ClickToMove : MonoBehaviour
  5. {
  6. NavMeshAgent navAgent;
  7. //The Start is just grabbing the 'NavMeshAgent' to the code
  8. void Start()
  9. {
  10. navAgent = GetComponent<NavMeshAgent>();
  11. }
  12. //Update means what you do to change what happends. Like Clicking for example! :D
  13. void Update()
  14. {
  15. //This part sends a line from the mouse to the terrain to make your character move
  16. RaycastHit hit;
  17. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  18. //The mover is assigned to the left click on your mouse, just like any MOBA game out there
  19. if (Input.GetMouseButtonUp(0))
  20. {
  21. //The 100 states that your mouse can send a line up to 100 units, no farther than that.
  22. if (Physics.Raycast(ray, out hit, 100))
  23.  
  24. {
  25. //Debug means it just sends it to the console, pretty much makin' sure that it works, It
  26. //sends the position u clicked on the terrain to console to see where you are clicking at
  27. Debug.Log(hit.point);
  28. //These Brackets at the very end here close all the statements so nothing interfear with it!
  29. }
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement