blob: 81a2b1b429fded71d906c69dcff5912639e44523 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
}
}
}
}
}
|