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.
34 lines
790 B
34 lines
790 B
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
|
|
public class ClickMove : MonoBehaviour
|
|
{
|
|
private Vector3 targetPosition;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hit;
|
|
if (Physics.Raycast(ray, out hit))
|
|
{
|
|
targetPosition = hit.point;
|
|
}
|
|
}
|
|
|
|
if (Vector3.Distance(transform.position, targetPosition) > 0.1f)
|
|
{
|
|
GetComponent<NavMeshAgent>().SetDestination(targetPosition);
|
|
}
|
|
}
|
|
}
|