Guest User

Untitled

a guest
Apr 23rd, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. public class move : MonoBehaviour {
  4.     NavMeshAgent agent;
  5.     public GameObject empty;
  6.     NavMeshHit navHit;
  7.     bool kounisou=false;
  8.     public GameObject cam;
  9.  
  10.  
  11.     void Awake () {
  12.         // Use GetGomponent in the Awake method rather than on Start
  13.         agent = GetComponent<NavMeshAgent> ();
  14.     }
  15.  
  16.  
  17.  
  18.     void Update () {
  19.         if (Input.GetMouseButtonUp (0)) {
  20.             RaycastHit hit;
  21.            
  22.             Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  23.             if (Physics.Raycast (ray, out hit, Mathf.Infinity)) {
  24.                 if (hit.collider != null) {
  25.                     if (hit.collider.tag == "edafos") {
  26.                        
  27.  
  28.                         NavMesh.SamplePosition (hit.point, out navHit, 1, -1);
  29.                        
  30.                         NavMeshPath navpath = new NavMeshPath();
  31.                         NavMesh.CalculatePath (transform.position, hit.point, -1, navpath);
  32.                         if (navpath.status == NavMeshPathStatus.PathComplete) {
  33.                             kounisou=true;
  34.                         }            
  35.                     }else if (hit.collider.tag == "koumpi") {
  36.                        
  37.  
  38.                             Instantiate (Resources.Load ("Cube1"), empty.transform.position, Quaternion.identity);
  39.                            
  40.                            
  41.                            
  42.  
  43.                     }
  44.                    
  45.                 }
  46.                
  47.             }
  48.         }if (kounisou) {
  49.         agent.SetDestination (navHit.position);
  50.             if (agent.transform.position==navHit.position){
  51.                 kounisou=false;
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment