Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ClickToMove : MonoBehaviour
- {
- NavMeshAgent navAgent;
- //The Start is just grabbing the 'NavMeshAgent' to the code
- void Start()
- {
- navAgent = GetComponent<NavMeshAgent>();
- }
- //Update means what you do to change what happends. Like Clicking for example! :D
- void Update()
- {
- //This part sends a line from the mouse to the terrain to make your character move
- RaycastHit hit;
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- //The mover is assigned to the left click on your mouse, just like any MOBA game out there
- if (Input.GetMouseButtonUp(0))
- {
- //The 100 states that your mouse can send a line up to 100 units, no farther than that.
- if (Physics.Raycast(ray, out hit, 100))
- {
- //Debug means it just sends it to the console, pretty much makin' sure that it works, It
- //sends the position u clicked on the terrain to console to see where you are clicking at
- Debug.Log(hit.point);
- //These Brackets at the very end here close all the statements so nothing interfear with it!
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement