diff options
Diffstat (limited to 'Assets/Scripts')
| -rw-r--r-- | Assets/Scripts/PlayerMovement.cs | 30 | ||||
| -rw-r--r-- | Assets/Scripts/PlayerMovement.cs.meta | 11 |
2 files changed, 41 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); + } + } + } +} diff --git a/Assets/Scripts/PlayerMovement.cs.meta b/Assets/Scripts/PlayerMovement.cs.meta new file mode 100644 index 0000000..30793c0 --- /dev/null +++ b/Assets/Scripts/PlayerMovement.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 12d4d72b91b49f045a12f8c1a7cac845 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |
