init
This commit is contained in:
commit
341a877b4a
2338 changed files with 1346408 additions and 0 deletions
25
Assets/NavMesh/Examples/Scripts/ClickToMove.cs
Normal file
25
Assets/NavMesh/Examples/Scripts/ClickToMove.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
// Use physics raycast hit from mouse click to set agent destination
|
||||
[RequireComponent(typeof(NavMeshAgent))]
|
||||
public class ClickToMove : MonoBehaviour
|
||||
{
|
||||
NavMeshAgent m_Agent;
|
||||
RaycastHit m_HitInfo = new RaycastHit();
|
||||
|
||||
void Start()
|
||||
{
|
||||
m_Agent = GetComponent<NavMeshAgent>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
if (Physics.Raycast(ray.origin, ray.direction, out m_HitInfo))
|
||||
m_Agent.destination = m_HitInfo.point;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue