Exemplo n.º 1
0
 private void EnemyTracking()
 {
     if (anim.GetInteger("action") != 2)
     {
         anim.SetInteger("facing", (int)currentFacing);
         if (roLo.walk && !roLo.AreYouStopped())
         {
             anim.SetInteger("action", 1);
         }
         else
         {
             anim.SetInteger("action", 0);
         }
     }
 }
        IEnumerator UpdateMovement()
        {
            Waypoint currentNodePos = pathfinding.TransformToWaypoint(transform);

            while (true)
            {
                recalculate = false;
                if (player && cNavMesh && RoomManager.gameSetupComplete && !roLo.dead)
                {
                    List <Waypoint> path = pathfinding.GetPath(player.transform, cNavMesh, currentNodePos);
                    if (path.Count > 1)
                    {
                        foreach (Waypoint node in path)
                        {
                            if (node == null)
                            {
                                break;
                            }
                            Vector3 pos       = new Vector3(node.position.x, node.position.y + 0.45f);
                            float   checkTime = Time.time;
                            while (Vector3.Distance(pos, transform.position) > 0.2f)
                            {
                                currentNodePos     = node;
                                transform.position = Vector3.MoveTowards(transform.position, pos, (roLo.loadout[(int)ItemLoc.legs].itemSpeed + roLo.loadout[(int)ItemLoc.body].itemSpeed - 0.5f) * Time.deltaTime);
                                roLo.walk          = true;
                                if (Time.time > (checkTime + 5))
                                {
                                    path = pathfinding.GetPath(player.transform, cNavMesh, node);
                                    break;
                                }
                                // Stop movement while attacking
                                while (roLo.AreYouStopped() || roLo.dead)
                                {
                                    yield return(null);
                                }
                                yield return(null);
                            }
                            roLo.walk = false;
                            if (recalculate || Vector3.Distance(player.transform.position, transform.position) < stoppingDistance)
                            {
                                break;
                            }
                        }
                    }
                }
                roLo.walk = false;
                yield return(null);
            }
        }