// Update is called once per frame
 void Update()
 {
     if (!HUDScript.isPaused && !HUDScript.isGameOver)
     {
         {
             if (mainPlayer.transform.localPosition.z > -9.29f && mainPlayer.transform.localPosition.z < 10.13f && mainPlayer.transform.localPosition.x > 8.01f)                  //z between -9.29 and 10.13			 x greater than 8.01
             {
                 agent.speed = 2.0f;
                 agent.SetDestination(mainPlayer.transform.position);
                 if (Vector3.Distance(transform.position, mainPlayer.transform.position) < 3)
                 {
                     hud.DecSanity(0.2f);
                 }
             }
             else if (agent.transform.localPosition.x != 8.97f && agent.transform.localPosition.z != -7.09f)                     //position	{(12.2, 0.1, -6.1)}	UnityEngine.Vector3
             {
                 agent.speed = 2.0f;
                 //target = new Vector3 (/8.97f, agent.transform.localPosition.y, -7.09f);
                 agent.SetDestination(returnPosition);
             }
             else
             {
                 agent.speed = 0.0f;
                 agent.transform.Rotate(new Vector3(0, 0, 0));
             }
         }
     }
     else
     {
         agent.speed = 0.0f;
     }
 }
 void Update()
 {
     //transform.position.Set (transform.position.x, -1.37f, transform.position.z);
     if (!HUDScript.isPaused && !HUDScript.isGameOver)
     {
         agent.speed = 2.0f;
         agent.SetDestination(target.position);
         if (!chasing)
         {
             if ((agent.transform.position - target.position).magnitude <= 3.0f)
             {
                 Vector3 rnddir = Random.insideUnitSphere * 10;
                 rnddir += transform.position;
                 NavMeshHit meshhit;
                 NavMesh.SamplePosition(rnddir, out meshhit, 10, 1);
                 target.position = new Vector3(meshhit.position.x, transform.position.y, meshhit.position.z);
                 agent.SetDestination(target.position);
             }
         }
         else if (chasing)
         {
             if ((agent.transform.position - target.position).magnitude <= 2.5f)
             {
                 agent.speed = 0;
             }
             else
             {
                 agent.speed = 2.0f;
             }
         }
         //chases the player so long as player is directly in front of it
         Vector3    fwd = transform.TransformDirection(Vector3.forward);
         RaycastHit hit;
         //increase y position to the transform.position and place that in Raycast
         if (Physics.Raycast(transform.position, fwd, out hit))
         {
             if (hit.transform == playerpos)
             {
                 chasing         = true;
                 target.position = new Vector3(playerpos.position.x, playerpos.position.y, playerpos.position.z);
                 agent.SetDestination(target.position);
             }
             else
             {
                 chasing = false;
             }
         }
         if (Vector3.Distance(transform.position, mainPlayer.transform.position) < 3)
         {
             hud.DecSanity(0.2f);
         }
     }
     else
     {
         agent.speed = 0;
     }
 }
Beispiel #3
0
 // Update is called once per frame
 void Update()
 {
     if (mainPlayer.transform.localPosition.z > 7.00f && mainPlayer.transform.localPosition.x > -23.0f && mainPlayer.transform.localPosition.x < -7.10f && mainPlayer.transform.localPosition.y < 1.0f)
     {
         //z greater than 7.00 and x between -23.00 and 7.17
         agent.speed = 2.0f;
         agent.SetDestination(mainPlayer.transform.position);
         if (Vector3.Distance(transform.position, mainPlayer.transform.position) < 3)
         {
             hud.DecSanity(0.2f);
         }
     }
     else if (agent.transform.localPosition.x != -21.19f && agent.transform.localPosition.z != 8.45f)             //position	{(12.2, 0.1, -6.1)}	UnityEngine.Vector3
     {
         agent.speed = 2.0f;
         //target = new Vector3 (/8.97f, agent.transform.localPosition.y, -7.09f);
         agent.SetDestination(returnPosition);
     }
     else
     {
         agent.speed = 0.0f;
         agent.transform.Rotate(new Vector3(0, 0, 0));
     }
 }