Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MoveToClickPoint.cs
- using UnityEngine;
- using UnityEngine.AI;
- // As found at https://docs.unity3d.com/Manual/nav-MoveToClickPoint.html
- public class MoveToClickPoint : MonoBehaviour
- {
- NavMeshAgent agent;
- void Start()
- {
- agent = GetComponent<NavMeshAgent>();
- }
- void Update()
- {
- if( Input.GetMouseButtonDown( 0 ) )
- {
- RaycastHit hit;
- if( Physics.Raycast( Camera.main.ScreenPointToRay( Input.mousePosition ), out hit, 100 ) )
- {
- agent.destination = hit.point;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement