Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
Obtener la longitud del renderizador de ruta

¿Cómo obtengo la longitud de todo el renderizador de Trail que se dibuja en Unity? Para el renderizador de línea, podemos lograr esto usando los puntos 1 y 2 de la línea, como:

 var length = (position2 - position1).magnitude;

Pero desafortunadamente no pude encontrar lo mismo para el renderizador de senderos ya que usa múltiples puntos. Entonces, ¿cómo logro esto?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Puede iterar a través de todos los puntos usando TrailRenderer.GetPositions como, por ejemplo

 public static class TrailRendererExtensions { public static float GetTrailLength(this TrailRenderer trailRenderer) { // You store the count since the created array might be bigger than the actual pointCount // Note: apparently the API is wrong?! There it says starting from version 2018.1 the parameter is "out" // if you get an error for the "out" anyway or if you use older versions instead use //var points = new Vector3[trailRenderer.positionCount]; //var count = trailRenderer.GetPositions(points); var count = trailRenderer.GetPositions(out var points); // If there are not at least 2 points .. well there is nothing to measure if(count < 2) return 0f; var length = 0f; // Store the first position var start = points[0]; // Iterate through the rest of positions for(var i = 1; i < count; i++) { // get the current position var end = points[i]; // Add the distance to the last position // basically the same as writing //length += (end - start).magnitude; length += Vector3.Distance(start, end); // update the start position for the next iteration start = end; } return length; } }

este es ahora un método de extensión, por lo que simplemente puede usarlo en cualquier parte de su proyecto como

 var length = yourTrailRenderer.GetTrailLength();
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda