using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; using UnityEngine.EventSystems; public class PersonTest : MonoBehaviour { private NavMeshAgent agent; void Start() { agent = GetComponent(); } // Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { if (!EventSystem.current.IsPointerOverGameObject()) { //Vector3 v = Input.mousePosition; //Vector3 worldv = Camera.main.ScreenToWorldPoint(v); //worldv.y = transform.position.y; //Debug.Log(v + ":" + worldv); //bool ok = agent.SetDestination(Camera.main.ScreenToWorldPoint(worldv)); //Debug.Log(ok); ////agent.Move(offfset); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.tag == "Road") { //Debug.Log(hit.transform.name); agent.SetDestination(hit.point); } else { //Debug.Log(hit.transform.name + "false"); agent.SetDestination(hit.point); } } } } } }