Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. // MoveToClickPoint.cs
  2. using UnityEngine;
  3. using UnityEngine.AI;
  4.  
  5. // As found at https://docs.unity3d.com/Manual/nav-MoveToClickPoint.html
  6.  
  7. public class MoveToClickPoint : MonoBehaviour
  8. {
  9.     NavMeshAgent agent;
  10.  
  11.     void Start()
  12.     {
  13.         agent = GetComponent<NavMeshAgent>();
  14.     }
  15.  
  16.     void Update()
  17.     {
  18.         if( Input.GetMouseButtonDown( 0 ) )
  19.         {
  20.             RaycastHit hit;
  21.  
  22.             if( Physics.Raycast( Camera.main.ScreenPointToRay( Input.mousePosition ), out hit, 100 ) )
  23.             {
  24.                 agent.destination = hit.point;
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement