This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.AI; | |
public class Movement : MonoBehaviour | |
{ | |
[SerializeField] | |
private Camera camera; | |
private string groundTag = "Ground"; | |
private NavMeshAgent agent; | |
private RaycastHit hit; | |
// Called when a script is enabled | |
void Start() | |
{ | |
agent = GetComponent<NavMeshAgent>(); | |
} | |
// Called once every frame | |
void Update() | |
{ | |
if (Input.GetMouseButtonDown(0)) | |
{ | |
Ray ray = camera.ScreenPointToRay(Input.mousePosition); | |
if (Physics.Raycast(ray, out hit, Mathf.Infinity)) | |
{ | |
if (hit.collider.CompareTag(groundTag)) | |
{ | |
agent.SetDestination(hit.point); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment