Esempio n. 1
0
 //This is done so that this class inherits from the method in the classNPC
 override public void test()
 {
     //It says here that for every GameObject called ObjectsTest that is in the Objects list in Instancias...
     foreach (GameObject ObjectsTest in Instancias.Objects)
     {
         //If the object is with the Zombie tag
         if (ObjectsTest.CompareTag("Zombie"))
         {
             //Here you check the distance between the object in the list and the Zombie; if it is smaller at a distance(5) then...
             if (Vector3.Distance(ObjectsTest.transform.position, transform.position) < distancia)
             {
                 //This causes the citizen to run from the Zombie in the opposite direction.
                 transform.position = Vector3.MoveTowards(transform.position, ObjectsTest.transform.position, -Speed);
                 //This is where the corutine that activates the states in classNPC
                 StopCoroutine(Movement());
             }
         }
     }
 }
Esempio n. 2
0
 //Here you create a method that you can call up from other classes that inherit from classNPC.
 virtual public void test()
 {
     //It says here that for each GameObject with the name ObjectsTest in the list of Instances called Objects.
     foreach (GameObject ObjectsTest in Instancias.Objects)
     {
         //It says here that if the object with the Citizen component or the object with the Hero component
         if (ObjectsTest.GetComponent <Citizen>() || ObjectsTest.GetComponent <Hero>())
         {
             //Here the distance between the object in the list and the zombie is checked; if it is smaller at a distance(5) then....
             if (Vector3.Distance(ObjectsTest.transform.position, transform.position) < distancia)
             {
                 //The state of both the Zombies and the citizens to be equal to pursuing
                 init.keep = state.pursuing;
                 //This tells you where the Zombie should go and how fast.
                 transform.position = Vector3.MoveTowards(transform.position, ObjectsTest.transform.position, Speed);
                 //This is where the corutine that activates the states in classNPC.
                 StopCoroutine(Movement());
             }
         }
     }
 }