private void NewWayPoint()
 {
     curIndexTarget++;
     if (curIndexTarget < way.Length)
     {
         target    = way[curIndexTarget];
         direction = (target.position - transform.position).normalized;
         cerebellum.LookAt(target);
         angle = cerebellum.rotation;
         waypointProperties = target.GetComponent <WaypointProperties>();
         action             = waypointProperties.Properties;
     }
     else
     {
         Destroy(way[0].gameObject);
         Destroy(gameObject);
     }
 }
示例#2
0
    IEnumerator RaycastAndMove()
    {
        running = true;
        hit     = Physics2D.Raycast(altWaypoint.transform.position, LookForward);
        if (hit.transform.gameObject != null && hit.transform.gameObject.CompareTag("Waypoint") == false)
        {
            index0      = UnityEngine.Random.Range(0, WaypointManager.Waypoints.Count);
            altWaypoint = WaypointManager.Waypoints[index0];
            LookForward = new Vector2(altWaypoint.transform.position.x, altWaypoint.transform.position.y + 0.5f);
            hit         = Physics2D.Raycast(altWaypoint.transform.position, LookForward);
            running     = false;
            yield return(null);
        }
        else
        {
            Waypoint       = WaypointManager.Waypoints[index0];
            MoveToPosition = Waypoint.transform.position;
            yield return(new WaitForSeconds(sec));

            running = false;
        }
    }