Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class move : MonoBehaviour {
- NavMeshAgent agent;
- public GameObject empty;
- NavMeshHit navHit;
- bool kounisou=false;
- public GameObject cam;
- void Awake () {
- // Use GetGomponent in the Awake method rather than on Start
- agent = GetComponent<NavMeshAgent> ();
- }
- void Update () {
- if (Input.GetMouseButtonUp (0)) {
- RaycastHit hit;
- Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
- if (Physics.Raycast (ray, out hit, Mathf.Infinity)) {
- if (hit.collider != null) {
- if (hit.collider.tag == "edafos") {
- NavMesh.SamplePosition (hit.point, out navHit, 1, -1);
- NavMeshPath navpath = new NavMeshPath();
- NavMesh.CalculatePath (transform.position, hit.point, -1, navpath);
- if (navpath.status == NavMeshPathStatus.PathComplete) {
- kounisou=true;
- }
- }else if (hit.collider.tag == "koumpi") {
- Instantiate (Resources.Load ("Cube1"), empty.transform.position, Quaternion.identity);
- }
- }
- }
- }if (kounisou) {
- agent.SetDestination (navHit.position);
- if (agent.transform.position==navHit.position){
- kounisou=false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment