diff options
Diffstat (limited to 'Assets/Scripts/PlayerMovement.cs')
| -rw-r--r-- | Assets/Scripts/PlayerMovement.cs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs new file mode 100644 index 0000000..c55b7a8 --- /dev/null +++ b/Assets/Scripts/PlayerMovement.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.AI; + +public class PlayerMovement : MonoBehaviour +{ + public LayerMask whatCanBeClickedOn; + + private UnityEngine.AI.NavMeshAgent myAgent; + + // Start is called before the first frame update + void Start() + { + myAgent = GetComponent <UnityEngine.AI.NavMeshAgent> (); + } + + // Update is called once per frame + void Update() + { + if (Input.GetMouseButtonDown(0)) { + Ray myRay = Camera.main.ScreenPointToRay (Input.mousePosition); + RaycastHit hitInfo; + + if(Physics.Raycast (myRay, out hitInfo, 100, whatCanBeClickedOn)) { + myAgent.SetDestination (hitInfo.point); + } + } + } +} |
