Пример #1
0
 // Update is called once per frame
 void Update()
 {
     if (!havePath)
     {
         path     = graph.Search(transform.position, player.transform.position);
         havePath = true;
     }
     else if (path.Count > 0)
     {
         Vector3 dir = path[0] - transform.position;
         dir.y = 0;
         if (dir.magnitude < Time.deltaTime * speed)
         {
             transform.position = new Vector3(path[0].x, transform.position.y, path[0].z);
             path.RemoveAt(0);
         }
         else
         {
             transform.position += dir.normalized * Time.deltaTime * speed;
         }
     }
 }