diff options
author | chai <215380520@qq.com> | 2024-05-23 10:10:23 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-05-23 10:10:23 +0800 |
commit | 81330a6b68d307937c262368a42a3fa4e9ad4207 (patch) | |
tree | 0616a08be385794e062fb616df4ffb503631ee08 /Other/NavMeshTest/Assets/Scripts/MoveToMouse.cs | |
parent | 8722a9920c1f6119bf6e769cba270e63097f8e25 (diff) |
+ NavMeshTest
Diffstat (limited to 'Other/NavMeshTest/Assets/Scripts/MoveToMouse.cs')
-rw-r--r-- | Other/NavMeshTest/Assets/Scripts/MoveToMouse.cs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Other/NavMeshTest/Assets/Scripts/MoveToMouse.cs b/Other/NavMeshTest/Assets/Scripts/MoveToMouse.cs new file mode 100644 index 0000000..81a2b1b --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/MoveToMouse.cs @@ -0,0 +1,34 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.AI; + +public class MoveToMouse : MonoBehaviour +{ + public Transform flag; + + private NavMeshAgent m_Agent; + + private void Awake() + { + m_Agent = GetComponent<NavMeshAgent>(); + } + + private void Update() + { + if(Input.GetMouseButtonDown(0)) + { + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + RaycastHit info; + if(Physics.Raycast(ray, out info, Mathf.Infinity, Physics.DefaultRaycastLayers)) + { + if(info.collider.gameObject.layer != LayerMask.NameToLayer("Prop")) + { + m_Agent.destination = info.point; + flag.position = info.point; + } + } + } + } + +} |