Advertisement
Guest User

IACircuito

a guest
Aug 30th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class IACircuito : MonoBehaviour {
  5.  
  6.  
  7.     NavMeshAgent navAg;
  8.      GameObject pos1;
  9.      GameObject pos2;
  10.      GameObject pos3;
  11.      GameObject pos4;
  12.      GameObject pos5;
  13.  
  14.     Vector3 target1;
  15.     Vector3 target2;
  16.     Vector3 target3;
  17.     Vector3 target4;
  18.     Vector3 target5;
  19.     Vector3 targetx;
  20.  
  21.  
  22.  
  23.  
  24.  
  25.     void Awake(){
  26.         navAg = GetComponent<NavMeshAgent> ();
  27.         pos1 = GameObject.FindGameObjectWithTag("Posizione1");
  28.         pos2 = GameObject.FindGameObjectWithTag("Posizione2");
  29.         pos3 = GameObject.FindGameObjectWithTag("Posizione3");
  30.         pos4 = GameObject.FindGameObjectWithTag("Posizione4");
  31.         pos5 = GameObject.FindGameObjectWithTag("Posizione5");
  32.         target1 = pos1.transform.position;
  33.         target2 = pos2.transform.position;
  34.         target3 = pos3.transform.position;
  35.         target4 = pos4.transform.position;
  36.         target5 = pos5.transform.position;
  37.     }
  38.     void Start(){
  39.         targetx = target1;
  40.         navAg.SetDestination(targetx);
  41.     }
  42.        
  43.     void OnTriggerEnter(Collider col){
  44.         if(col.tag==("Posizione5")){
  45.             targetx = target1;
  46.             navAg.SetDestination(targetx);
  47.         } else if (col.tag == ("Posizione4")){
  48.             targetx = target5;
  49.             navAg.SetDestination(targetx);
  50.         } else if (col.tag == ("Posizione3")){
  51.             targetx = target4;
  52.             navAg.SetDestination(targetx);
  53.         } else if (col.tag == ("Posizione2")){
  54.             targetx = target3;
  55.             navAg.SetDestination(targetx);
  56.         } else if (col.tag == ("Posizione1")){
  57.             targetx = target2;
  58.             navAg.SetDestination(targetx);
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement