You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
50 lines
1.5 KiB
3 years ago
|
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<NavMeshAgent>();
|
||
|
}
|
||
|
|
||
|
// 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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|